A
A
Artemm10292016-11-21 15:34:32
Visual Basic
Artemm1029, 2016-11-21 15:34:32

How to loop through Checkboxes in VBA?

The code for the two checkboxes separately works:
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
Cells(3, 2).Copy Worksheets("Query").Cells(3, 2)
Else: Worksheets("Query" ).Cells(3, 2).Clear
End If
End Sub
Private Sub CheckBox2_Click()
If CheckBox2.Value = True Then
Cells(4, 2).Copy Worksheets("Query").Cells(4, 2)
Else: Worksheets ("Query").Cells(4, 2).Clear
End If
End Sub
I'm trying to write a loop and it doesn't work, what's wrong?
Private Sub CheckBoxes_Click()
Dim i As Integer
Dim j As Integer
j = i + 2
For i = 3 To 12
If CheckBox(i).Value = True Then
Cells(j, 2).Copy Worksheets("Query").Cells(j, 2)
Else: Worksheets("Query").Cells(j, 2).Clear
End If
End Sub
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Fedoryan, 2016-11-21
@AnnTHony

www.planetaexcel.ru/forum/?FID=8&PAGE_NAME=read&TI...
www.excel-vba.ru/forum/index.php?topic=1901.0

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question