help with checkbox in For Loop


Posted by Mike on August 21, 2001 7:43 AM

I am trying to put a series of checkboxes into a for loop. The loop will look for 'true' checkboxes and if a checkbox is 'true' an action will be performed (data pulled in and stored from other excel files). Currently the user puts an 'X' in a specific cell for the action to take place, but I would like to replace it with a checkbox.

Somehow the for loop needs to cycle through checkbox1 to checkbox18. ("For Checkbox1 to Checkbox18" doesn't work). Then the IF statement inside the For Loop needs to examine the checkbox ("IF Checkbox(?).Value = True Then")

any ideas?

Current For/If commands

For Row = 8 To 25
If Cells(Row, 4) = "X" Then
{Perform action}
Endif
Next Row

Posted by Doug on August 21, 2001 8:46 AM

Try building an array of checkboxes.

Dim Boxes(1 to 2) as Object

Set Boxes(1)=CheckBox1
Set Boxes(2)=CheckBox2

For i=1 to 2
If Boxes(1).Value then
<Perform Action>
End If
Next i


Hope this helps...



Posted by Mike on August 23, 2001 8:13 AM

I tried your suggestion below and this is what my code started with, but got stuck at the first Set line with error: Run-time error '424':
Object Required

Any Idea what's wrong?


SubDir = Cells(10, 12)
Dim Boxes1(1 To 18) As Object
Set Boxes1(1) = CheckBox1
Set Boxes1(2) = CheckBox2
Set Boxes1(3) = CheckBox3

: I am trying to put a series of checkboxes into a for loop. The loop will look for 'true' checkboxes and if a checkbox is 'true' an action will be performed (data pulled in and stored from other excel files). Currently the user puts an 'X' in a specific cell for the action to take place, but I would like to replace it with a checkbox. : Somehow the for loop needs to cycle through checkbox1 to checkbox18. ("For Checkbox1 to Checkbox18" doesn't work). Then the IF statement inside the For Loop needs to examine the checkbox ("IF Checkbox(?).Value = True Then") : any ideas? : Current For/If commands : For Row = 8 To 25 : If Cells(Row, 4) = "X" Then : {Perform action} : Endif : Next Row