I have 20 checkboxes, and 20 objects. I want to load the user form with the checkboxes, and for each checkbox selected, I want to select that object. So CheckBox1 corresponds to Object1 and so forth to 20. Any ideas?
Printable View
I have 20 checkboxes, and 20 objects. I want to load the user form with the checkboxes, and for each checkbox selected, I want to select that object. So CheckBox1 corresponds to Object1 and so forth to 20. Any ideas?
What kind of objects? And what do you exactly mean by "select that object"?Quote:
Originally Posted by mike3847
Assuming that you're checkbox's are in a array you can use this.
VB Code:
Private Sub Check1_Click(Index As Integer) If Check1(Index).Value = vbChecked Then 'Code here End If End Sub
Checks to see if the check box is Checked, then runs the code you want it to.
They're just autoshapes. Like I want to use:
ActiveSheet.Shapes("Shape1").Select
but only if CheckBox 1 is checked on the user form.
I tryed the above code, but cannot get it to work. I can't even figure out how to get the value of the checkbox (1, true, 0, or false). Why is this wrong?
sub test()
Load StateSelect
CheckBox1.Value = True
StateSelect.Show
end sub()
Is this Excel VBA?
Values of checkboxes are expressed as 'checked' or 'unchecked' which I think represent 0 or 1...Quote:
Originally Posted by mike3847
Why it isn't a boolean like an option box, I dunno.... I guess some weird microsoft thing.... :confused:
you would end up like
VB Code:
sub test() Load StateSelect CheckBox1.Value = Checked 'checked instead of true StateSelect.Show end sub()
Actually, they are either vbChecked of vbUnChecked which represent 0 and 1. Both of these will workQuote:
Originally Posted by TheBigB
But, I would recommend always using the vb constant as it makes the code much, much easier to understand when reviewing it.VB Code:
Private Sub Command1_Click() If Check1.Value = 0 Then MsgBox "No" Else MsgBox "Yes" End If End Sub Private Sub Command1_Click() If Check1.Value = vbUnChecked Then MsgBox "No" Else MsgBox "Yes" End If End Sub
doesn't work. Says "Object Required"
What doesn't work?Quote:
Originally Posted by mike3847
Are you using VB6 or VBA?
I am using VB6 within Excel 2000.
VB6 is not within anything. It is a completely stand-along development platform that is totally outside of any Office product. That is why my code didn't work. You really aren't using VB6. You are using Excel VBA, and there are many, many features of VB that VBA does not support.Quote:
Originally Posted by mike3847
I'm moving your VBA question to Office Development.
I was just going off what my Visual Basic says, and that is 6.0. It is within excel. I wasn't aware that it was referred to as VBA.
Incidentally, in VBA the checkbox does not have a Checked property. It has a Value property, which is boolean.