T
tudobeo
Guest
Bonjour,
J'aimerai pouvoir étendre un code VBA qui fonctionne sur une seule ligne, cellule B2 à 8 lignes en plus (cellules B2 à B10)
Le code (du site de BOISGONTIER - merci au passage pour cette mine d'information) est le suivant :
Private Sub Worksheet_Change(ByVal Target As Range)
Set f = Sheets("listes")
If Target.Address = "$B$2" And Target.Count = 1 Then
If Target <> "" Then
If IsError(Application.Match(Target.Value, [choix1], 0)) Then
If MsgBox("On ajoute?", vbYesNo) = vbYes Then
[choix1].End(xlToRight).Offset(0, 1) = Target.Value
c = f.Range("choix2").Column
n = Application.CountA([choix1])
f.Range(f.Cells(1, c), f.Cells(10, c + n)).Sort _
Key1:=f.Cells(1, c), Order1:=xlAscending, Header:=xlNo, _
Orientation:=xlLeftToRight
Else
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
Else
Target.Offset(0, 1) = f.Range("choix2")(1).Offset(1, Application.Match(Target, [choix1], 0) - 1)
End If
End If
End If
Merci pour votre aide.
J'aimerai pouvoir étendre un code VBA qui fonctionne sur une seule ligne, cellule B2 à 8 lignes en plus (cellules B2 à B10)
Le code (du site de BOISGONTIER - merci au passage pour cette mine d'information) est le suivant :
Private Sub Worksheet_Change(ByVal Target As Range)
Set f = Sheets("listes")
If Target.Address = "$B$2" And Target.Count = 1 Then
If Target <> "" Then
If IsError(Application.Match(Target.Value, [choix1], 0)) Then
If MsgBox("On ajoute?", vbYesNo) = vbYes Then
[choix1].End(xlToRight).Offset(0, 1) = Target.Value
c = f.Range("choix2").Column
n = Application.CountA([choix1])
f.Range(f.Cells(1, c), f.Cells(10, c + n)).Sort _
Key1:=f.Cells(1, c), Order1:=xlAscending, Header:=xlNo, _
Orientation:=xlLeftToRight
Else
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
Else
Target.Offset(0, 1) = f.Range("choix2")(1).Offset(1, Application.Match(Target, [choix1], 0) - 1)
End If
End If
End If
Merci pour votre aide.