samedi 4 janvier 2020

how to loop checkboxes

Please help me with this vba. i have 20 checkboxes named checkbox1 to checkbox20. I would like to write a vba that record the username in column B when each checkbox is checked. For example, when a username click on checkbox1, B1 would populate the username, if checkbox2 is clicked, B2 would populate username. I know how to write for each checkbox and copy it 20 times. Please help me combine them into one sub. Thanks in advance for your help. So far i came up with these codes but not working.

Private Sub CheckBox1_Click()

Dim i As Integer

For i = 1 To 20

If Me.CheckBox & i = True Then

Range("b1" & i).Value = Environ("USERNAME")

Else: Range("b1" & i).Value = ""

End If

Next

End Sub




Aucun commentaire:

Enregistrer un commentaire