Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88854

how to loop checkboxes

$
0
0

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

Viewing all articles
Browse latest Browse all 88854


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>