Aug 26 2022 06:36 AM
Good morning
I can't debug a routine assigned to a Button's OnAction. Debugging just doesn't fit. I have attached the code to understand better. Anyone know how to debug?
Thank you
Fabrizio
Public Sub Rettangoloconangoliarrotondati3_Click()
Dim btn As Button, t As Range, sht As Worksheet, i As Long
Dim lRiga As Long
Set sht = Sheets("FORMARTICOLI")
'sht.Buttons.Delete
lRiga = sht.Range("A" & sht.Rows.Count).End(xlUp).Row
For i = 2 To lRiga 'sht.Cells(Rows.Count, "A").End(xlUp).Row 'Numero righe
Set t = sht.Cells(i, 6) 'Colonna dove viene creato il bottone
Set btn = sht.Buttons.Add(t.Left, t.Top, t.Width, t.Height)
With btn
.OnAction = "CreateButton" 'Azione del bottone creato
.Caption = "Segna Articolo : " & sht.Cells(i, 2).Value
.Name = "btn" & sht.Cells(i, 2).Value & "_" & i
End With
Next i
End Sub
Public Sub CreateButton()
Dim RowNumber As Long, sht As Worksheet
Dim c As Range
Set sht = ActiveSheet
MsgBox Application.Caller
RowNumber = CLng(Split(Application.Caller, "_")(1))
Set c = sht.Cells(RowNumber, "F")
If c.Value = vbNullString Then
c.Value = "User: " & Application.UserName & vbNewLine & "Date: " & Date
If Date <= ActiveSheet.Cells(RowNumber, "E").Value Then
c.font.color = RGB(1, 125, 33)
c.Interior.color = RGB(0, 255, 127)
Else
c.font.color = vbRed
c.Interior.color = RGB(255, 204, 204)
End If
Else
c.Value = vbNullString
c.Interior.ColorIndex = 2
c.font.color = vbBlack
End If
End Sub