I have 20 checkboxes named checkbox1 to checkbox20.
I would like to record the username in column B when each checkbox is checked.
For example, when a user clicks on checkbox1, B1 would populate the username, if checkbox2 is clicked, B2 would populate username.
I know how to write code for each checkbox and copy it 20 times. How can I combine them into one sub?
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

Public WithEvents ctl As MSForms.CheckBoxand createPrivate Sub ctl_Click()orPrivate Sub ctl_Change()which will handle checkbox event, then create 20 instances of the class and assign each checkbox to each instance within loop. Note you should use Form Controls Check Boxes.