XL 2013 utilisation Worksheet_SelectionChange(ByVal Target As Range)

cyrikou

XLDnaute Occasionnel
bonjour à tous,
J'aimerai n'utiliser qu'une plage de données spécifique pour qu'a chaque fois qu'un évènement intervient dessus, les tests s'effectuent automatiquement, voici un bout du code :

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Long
Dim j As Long
'surinam
If Cells(9, 5) <> "Surinam" Then

  'gain set
  For i = 6 To 8
  If Cells(i, 5) = 21 Then
  Cells(i, 8) = 1
  End If
  Next i

  'résultat rencontre
  If Cells(9, 8) = 2 Then
  Cells(9, 5) = "Surinam"
  MsgBox "Vainqueur du Match : Surinam"
  End If
  
  
End If

Et voici la plage de cellules où doit intervenir les changements :
E6 :F9

Merci d'avance
 

Papou-net

XLDnaute Barbatruc
Re : utilisation Worksheet_SelectionChange(ByVal Target As Range)

Bonsoir cyrikou,

Pas sûr d'avoir bien compris la finalité du code mais je te propose de tester si la cellule sélectionnée est dans la plage E6:F9

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Long
Dim j As Long
If Not Intersect([E6:F9], Target) Is Nothing Then
   'surinam
   If Cells(9, 5) <> "Surinam" Then
     'gain set
     For i = 6 To 8
       If Cells(i, 5) = 21 Then  Cells(i, 8) = 1
     Next i
   End If
   'résultat rencontre
   If Cells(9, 8) = 2 Then
     Cells(9, 5) = "Surinam"
     MsgBox "Vainqueur du Match : Surinam"
  End If
End If
A +

Cordialement.