Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default CheckBox question

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default CheckBox question

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default CheckBox question

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default CheckBox question

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default CheckBox question

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default CheckBox question

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checkbox Question MCrum Excel Discussion (Misc queries) 1 January 15th 07 12:38 PM
Checkbox question Adam Kroger Excel Discussion (Misc queries) 0 December 19th 05 12:41 PM
Checkbox question Patrick Simonds Excel Programming 6 July 31st 05 05:49 PM
CheckBox question Frank Rudd via OfficeKB.com Excel Programming 2 July 1st 05 12:35 AM
CheckBox question Sheldon Excel Programming 6 January 25th 05 05:11 PM


All times are GMT +1. The time now is 10:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"