Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You have 20 checkboxes on a Userform and you want to select 20 corresponding
objects on a worksheet if the checkbox is checked. What is the correlation between the names of objects and the name of the checkboxes. do they both end in the same 2 digit numbers? Is the root name the same for all the objects? Waht is it? Are you sure you can't just use a list of names and work with the objects rather than selecting them? If the checkboxes are not on a userform - they are on a worksheet, are the from the control toolbox toolbar or the forms toolbar? -- Regards, Tom Ogilvy "Mike" wrote: 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? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Checkboxes are on a userform. And Object1 goes with CheckBox 1, Object2 goes,
with CheckBox2, and so forth to 20. "Tom Ogilvy" wrote: You have 20 checkboxes on a Userform and you want to select 20 corresponding objects on a worksheet if the checkbox is checked. What is the correlation between the names of objects and the name of the checkboxes. do they both end in the same 2 digit numbers? Is the root name the same for all the objects? Waht is it? Are you sure you can't just use a list of names and work with the objects rather than selecting them? If the checkboxes are not on a userform - they are on a worksheet, are the from the control toolbox toolbar or the forms toolbar? -- Regards, Tom Ogilvy "Mike" wrote: 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? |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
this worked for me:
Private Sub CommandButton1_Click() Dim cbox As MSForms.CheckBox Dim v() As Variant Dim i As Long i = 0 ReDim v(0 To 0) For Each ctrl In Me.Controls If TypeOf ctrl Is MSForms.CheckBox Then Set cbox = ctrl If cbox.Value = True Then ReDim Preserve v(0 To i) If Len(ctrl.Name) = 9 Then v(i) = "Object" & Right(ctrl.Name, 1) Else v(i) = "Object" & Right(ctrl.Name, 2) End If i = i + 1 End If End If Next If i = 1 Then ActiveSheet.Shapes(v(0)).Select Else ActiveSheet.Shapes.Range(v).Select End If End Sub -- Regards, Tom Ogilvy "Mike" wrote: Checkboxes are on a userform. And Object1 goes with CheckBox 1, Object2 goes, with CheckBox2, and so forth to 20. "Tom Ogilvy" wrote: You have 20 checkboxes on a Userform and you want to select 20 corresponding objects on a worksheet if the checkbox is checked. What is the correlation between the names of objects and the name of the checkboxes. do they both end in the same 2 digit numbers? Is the root name the same for all the objects? Waht is it? Are you sure you can't just use a list of names and work with the objects rather than selecting them? If the checkboxes are not on a userform - they are on a worksheet, are the from the control toolbox toolbar or the forms toolbar? -- Regards, Tom Ogilvy "Mike" wrote: 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? |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Tom, thanks. This makes sense and should work, but I'm still having problems.
I am showing the form in one sub, and then have the Command Button Sub like you have below for the OK button on the form. When I step through it, it gets to the part "If TypeOf Ctrl" and then jumps down to the End If. I assume the Me.Controls, the Me is the Userform name, right? So I replaced that with my userform name. Looks like it's not recognizing the controls as checkboxes. "Tom Ogilvy" wrote: this worked for me: Private Sub CommandButton1_Click() Dim cbox As MSForms.CheckBox Dim v() As Variant Dim i As Long i = 0 ReDim v(0 To 0) For Each ctrl In Me.Controls If TypeOf ctrl Is MSForms.CheckBox Then Set cbox = ctrl If cbox.Value = True Then ReDim Preserve v(0 To i) If Len(ctrl.Name) = 9 Then v(i) = "Object" & Right(ctrl.Name, 1) Else v(i) = "Object" & Right(ctrl.Name, 2) End If i = i + 1 End If End If Next If i = 1 Then ActiveSheet.Shapes(v(0)).Select Else ActiveSheet.Shapes.Range(v).Select End If End Sub -- Regards, Tom Ogilvy "Mike" wrote: Checkboxes are on a userform. And Object1 goes with CheckBox 1, Object2 goes, with CheckBox2, and so forth to 20. "Tom Ogilvy" wrote: You have 20 checkboxes on a Userform and you want to select 20 corresponding objects on a worksheet if the checkbox is checked. What is the correlation between the names of objects and the name of the checkboxes. do they both end in the same 2 digit numbers? Is the root name the same for all the objects? Waht is it? Are you sure you can't just use a list of names and work with the objects rather than selecting them? If the checkboxes are not on a userform - they are on a worksheet, are the from the control toolbox toolbar or the forms toolbar? -- Regards, Tom Ogilvy "Mike" wrote: 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? |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Still out there Tom?
"Mike" wrote: Tom, thanks. This makes sense and should work, but I'm still having problems. I am showing the form in one sub, and then have the Command Button Sub like you have below for the OK button on the form. When I step through it, it gets to the part "If TypeOf Ctrl" and then jumps down to the End If. I assume the Me.Controls, the Me is the Userform name, right? So I replaced that with my userform name. Looks like it's not recognizing the controls as checkboxes. "Tom Ogilvy" wrote: this worked for me: Private Sub CommandButton1_Click() Dim cbox As MSForms.CheckBox Dim v() As Variant Dim i As Long i = 0 ReDim v(0 To 0) For Each ctrl In Me.Controls If TypeOf ctrl Is MSForms.CheckBox Then Set cbox = ctrl If cbox.Value = True Then ReDim Preserve v(0 To i) If Len(ctrl.Name) = 9 Then v(i) = "Object" & Right(ctrl.Name, 1) Else v(i) = "Object" & Right(ctrl.Name, 2) End If i = i + 1 End If End If Next If i = 1 Then ActiveSheet.Shapes(v(0)).Select Else ActiveSheet.Shapes.Range(v).Select End If End Sub -- Regards, Tom Ogilvy "Mike" wrote: Checkboxes are on a userform. And Object1 goes with CheckBox 1, Object2 goes, with CheckBox2, and so forth to 20. "Tom Ogilvy" wrote: You have 20 checkboxes on a Userform and you want to select 20 corresponding objects on a worksheet if the checkbox is checked. What is the correlation between the names of objects and the name of the checkboxes. do they both end in the same 2 digit numbers? Is the root name the same for all the objects? Waht is it? Are you sure you can't just use a list of names and work with the objects rather than selecting them? If the checkboxes are not on a userform - they are on a worksheet, are the from the control toolbox toolbar or the forms toolbar? -- Regards, Tom Ogilvy "Mike" wrote: 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? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Checkbox Question | Excel Discussion (Misc queries) | |||
Checkbox question | Excel Discussion (Misc queries) | |||
Checkbox question | Excel Programming | |||
CheckBox question | Excel Programming | |||
CheckBox question | Excel Programming |