Nom de zone dans VBA sous forme [zone & i]

Bonjour les grands experts

Y a t'il un moyen de compacter le code joint en mettant quelque chose du type eval("zone"&i) comme en javascript ou à l'image d'INDIRECT ?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect([zone1], Target) Is Nothing And Target.Count = 1 Then
        MsgBox "ici zone1"
    End If
    If Not Intersect([zone2], Target) Is Nothing And Target.Count = 1 Then
        MsgBox "ici zone2"
    End If
    If Not Intersect([zone3], Target) Is Nothing And Target.Count = 1 Then
        MsgBox "ici zone3"
    End If
    If Not Intersect([zone4], Target) Is Nothing And Target.Count = 1 Then
        MsgBox "ici zone4"
    End If
End Sub
22zonage.xlsm (14.65 Ko)

Bonsoir Steelson,

Une piste ?:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Dim i&
  If Target.Count <> 1 Then Exit Sub
    For i = 1 To 4
      If Not Intersect(Range("zone" & i), Target) Is Nothing Then MsgBox "ici zone" & i
    Next i
End Sub

bonjour,

Je ne vois que ça :

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
For i = 1 To 4
    If Not Intersect(Range("zone" & i), Target) Is Nothing And Target.Count = 1 Then MsgBox "ici zone " & i
Next
End Sub

[EDIT] Grillé !

A+

Ah ben merci ... je n'y avais même pas pensé, pfttt !

Rechercher des sujets similaires à "nom zone vba forme"