Hello Hello,

Je débute sur VBA, j'essaie de créer une macro pour identifier automatiquement des taches dans une liste d'action:
colonne A = catégorie d'action (5 phases différentes)
et je veux pouvoir insérer des nouvelles actions qui se numérotent automatiquement en 1,2,3 etc

J'ai trouvé un exemple de fichier sur lequel ça fonctionne avec ce code:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Range, c As Range, s As String, n As Integer, m As Integer
  If Not Intersect(Target, Columns("B")) Is Nothing And Target.Count = 1 Then
    s = Left(UCase(Target.Value), 1)
    If s = "L" Or s = "B" Then
      Set r = Range("B1", Cells(Rows.Count, "B").End(xlUp))
      For Each c In r.Cells
        n = Val(Replace(c.Value, s, "0"))
        If n > m Then m = n
      Next c
      Application.EnableEvents = False
      Target.Value = s & Format(m + 1, "000")
      Application.EnableEvents = True
    End If
  End If
End Sub
Je l'ai adapté à mes besoins en mettant:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Range, c As Range, s As String, n As Integer, m As Integer
  If Not Intersect(Target, Columns("A")) Is Nothing And Target.Count = 1 Then
    s = Left(UCase(Target.Value), 1)
    If s = "compounding" Or s = "filling" Or s = "IV" Or s = "Transversal" Or s = "WHS avant formu" Then
      Set r = Range("A1", Cells(Rows.Count, "A").End(xlUp))
      For Each c In r.Cells
        n = Val(Replace(c.Value, s, "0"))
        If n > m Then m = n
      Next c
      Application.EnableEvents = False
      Target.Value = s & Format(m + 1, "000")
      Application.EnableEvents = True
    End If
  End If
End Sub
Mais quand j'insère ce code via VBA dans excel, ça n'apparaît pas dans mes macros et le système détecte une erreur sur la ligne:
If Not Intersect(Target, Columns("A")) Is Nothing And Target.Count = 1 Then

Si quelqu'un peut m'éclairer SVP