Bonjour,
voici un exemple,
Sub AjoutBouton()
Dim Nom As String, i As Long, y As Integer
Dim l As Double, t As Double, w As Double, h As Double
Dim Bouton As Object
EffaceBouton
For y = 10 To 11
For i = 5 To 42
With Cells(i, y) 'colonne J
l = .Left + 1
t = .Top + 1
w = .Width - 1
h = .Height - 1
End With
With ActiveSheet
Set Bouton = .Buttons.Add(l, t, w, h)
With Bouton
Select Case y
Case 10: .Characters.Text = "OK": .OnAction = "OKV"
Case 11: .Characters.Text = "KO": .OnAction = "KOV"
End Select
End With
End With
Next i
Next y
End Sub
Sub EffaceBouton()
For Each sh In ActiveSheet.Shapes
If sh.TextFrame.Characters.Text = "OK" Then sh.Delete
Next
End Sub
Sub OKV()
Nom = Application.Caller
rw = ActiveSheet.Shapes(Nom).TopLeftCell.Row
Cells(rw, 8).Interior.Color = 5287936
End Sub
Sub KOV()
Nom = Application.Caller
rw = ActiveSheet.Shapes(Nom).TopLeftCell.Row
Cells(rw, 8).Interior.Color = 255
End Sub
edit:
modifier la macro:
Sub EffaceBouton()
For Each sh In ActiveSheet.Shapes
If sh.TextFrame.Characters.Text = "OK" Then sh.Delete
Next
End Sub
par celle-ci:
Sub EffaceBouton()
For Each sh In ActiveSheet.Shapes
With sh.TextFrame.Characters
If .Text = "OK" Or .Text = "KO" Then sh.Delete
End With
Next
End Sub