Si deux plage s'entrecroise, alors...

  • Initiateur de la discussion Initiateur de la discussion pacoako
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

pacoako

XLDnaute Occasionnel
Bonjours à tous!

Je cherche une façon d'obtenir une valeur boolean si 2 plages de cellules s'entrecroisent..


Est-ce qu'il y a déjà une méthode existante dans VBA pour ça??

Merci!
 
Re : Si deux plage s'entrecroise, alors...

Bonsoir,
Méthode Intersect
Code:
Set plage1 = Range([I]ta plage 1[/I])
Set plage2 = Range([I]ta plage 2[/I])
If Not Application.Intersect(plage1, plage2) Is Nothing Then Flag = True
A+
kjin
 
Re : Si deux plage s'entrecroise, alors...

Merci Kjin!

J'ai trouvé ceci en surfant... si ça peut aider quelqu'un dans le futur!

With the function below you can determine if a cell is within a given range:
Function InRange(Range1 As Range, Range2 As Range) As Boolean
' returns True if Range1 is within Range2
Dim InterSectRange As Range
Set InterSectRange = Application.Intersect(Range1, Range2)
InRange = Not InterSectRange Is Nothing
Set InterSectRange = Nothing
End Function


Sub TestInRange()
If InRange(ActiveCell, Range("A1😀100")) Then
' code to handle that the active cell is within the right range
MsgBox "Active Cell In Range!"
Else
' code to handle that the active cell is not within the right range
MsgBox "Active Cell NOT In Range!"
End If
End Sub


A+
 
Re : Si deux plage s'entrecroise, alors...

Bonsoir à tous
Un problème avec le message précédent.
  1. premier commentaire :
    With the function below you can determine if a cell is within a given range:
    i.e. Cette fonction renseigne sur l'appartenance d'une cellule à un plage donnée :
    _
  2. Deuxième commentaire :
    ' returns True if Range1 is within Range2
    i.e. ' Renvoie VRAI si la plage "Range1" est incluse dans la plage "Range2".
Deux commentaires contradictoires !
_
Si le premier est exact, =InRange(C2:E2;E1:E3) doit renvoyer un message d'erreur puisque C2:E2 ne désigne pas une cellule, mais une plage de cellules.
Si le second est exact, =InRange(C2:E2;E1:E3) doit renvoyer FALSE puisque la plage C2:E2 n'est pas incluse dans E1:E3.
Or =InRange(C2:E2;E1:E3) renvoie... ...VRAI.
_
Conclusion : Aucun n'est exact ! Ces ricains racontent n'importe quoi.
Un seul commentaire correct en Français pour remplacer ces inepties :
La fonction InRange dit si l'intersection de deux plages n'est pas vide.
_
Propositions (en Français).​
Conforme au premier commentaire :
Code:
Function CelluleDansLaPlage(Plage1 As Range, Plage2 As Range)
[COLOR="SeaGreen"][B]' Renvoie VRAI si la CELLULE "Plage1" est incluse dans la PLAGE "Plage2".[/B][/COLOR]
   If Plage1.Count <> 1 Then CelluleDansLaPlage = Evaluate("NA()"): Exit Function
Dim PlageIntersection As Range
   Set PlageIntersection = Application.Intersect(Plage1, Plage2)
   If Not PlageIntersection Is Nothing Then CelluleDansLaPlage = (PlageIntersection.Address = Plage1.Address)
   Set PlageIntersection = Nothing 'Ligne facultative.
End Function
Conforme au deuxième commentaire :
Code:
Function PlageDansLaPlage(Plage1 As Range, Plage2 As Range) As Boolean
[COLOR="SeaGreen"][B]' Renvoie VRAI si la PLAGE "Plage1" est incluse dans la PLAGE "Plage2".[/B][/COLOR]
Dim PlageIntersection As Range
   Set PlageIntersection = Application.Intersect(Plage1, Plage2)
   If Not PlageIntersection Is Nothing Then PlageDansLaPlage = (PlageIntersection.Address = Plage1.Address)
   Set PlageIntersection = Nothing 'Ligne facultative.
End Function
ROGER2327
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
6
Affichages
339
Retour