Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default For each...loop for checkboxes

I have a userform that has several (30) checkboxes and
want to test which ones have been selected by showing the
checkbox names through a messagebox.

I started my code off like this once the commandbutton on
the userform has been selected:

private sub commandbutton1_click()

dim r as checkbox
dim w as string

w = ""

for each r in userform1
if r.value then
w = w & r.caption & vbcr
end if
next

end sub

But it appears that I am not getting the right
object/collection combination.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default For each...loop for checkboxes

Private Sub commandbutton1_click()

Dim r As Control
Dim w As String

w = ""

For Each r In UserForm2.Controls
If TypeOf r Is msforms.CheckBox Then
If r.Value Then
w = w & r.Caption & vbCr
End If
End If
Next
msgbox w
End Sub

Tested in xl97

--
Regards,
Tom Ogilvy


Steven Cheng wrote in message
...
I have a userform that has several (30) checkboxes and
want to test which ones have been selected by showing the
checkbox names through a messagebox.

I started my code off like this once the commandbutton on
the userform has been selected:

private sub commandbutton1_click()

dim r as checkbox
dim w as string

w = ""

for each r in userform1
if r.value then
w = w & r.caption & vbcr
end if
next

end sub

But it appears that I am not getting the right
object/collection combination.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default For each...loop for checkboxes

Tom,

Can you explain the difference between the second line of your For
loop and the following:

If TypeName(r) = "CheckBox" Then

Thanks,

Doug

On Tue, 5 Aug 2003 01:19:38 -0400, "Tom Ogilvy"
wrote:

Private Sub commandbutton1_click()

Dim r As Control
Dim w As String

w = ""

For Each r In UserForm2.Controls
If TypeOf r Is msforms.CheckBox Then
If r.Value Then
w = w & r.Caption & vbCr
End If
End If
Next
msgbox w
End Sub

Tested in xl97


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default For each...loop for checkboxes

That is just another way to check. - only danger there is you don't spell
CheckBox exactly right.

Regards,
Tom Ogilvy

Doug Glancy wrote in message
...
Tom,

Can you explain the difference between the second line of your For
loop and the following:

If TypeName(r) = "CheckBox" Then

Thanks,

Doug

On Tue, 5 Aug 2003 01:19:38 -0400, "Tom Ogilvy"
wrote:

Private Sub commandbutton1_click()

Dim r As Control
Dim w As String

w = ""

For Each r In UserForm2.Controls
If TypeOf r Is msforms.CheckBox Then
If r.Value Then
w = w & r.Caption & vbCr
End If
End If
Next
msgbox w
End Sub

Tested in xl97




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default For each...loop for checkboxes

Tom/Doug...thanks. But this implies that it is looking
for a forms control, right? As opposed to its ActiveX
counterpart?
-----Original Message-----
That is just another way to check. - only danger there

is you don't spell
CheckBox exactly right.

Regards,
Tom Ogilvy

Doug Glancy wrote in message
.. .
Tom,

Can you explain the difference between the second line

of your For
loop and the following:

If TypeName(r) = "CheckBox" Then

Thanks,

Doug

On Tue, 5 Aug 2003 01:19:38 -0400, "Tom Ogilvy"


wrote:

Private Sub commandbutton1_click()

Dim r As Control
Dim w As String

w = ""

For Each r In UserForm2.Controls
If TypeOf r Is msforms.CheckBox Then
If r.Value Then
w = w & r.Caption & vbCr
End If
End If
Next
msgbox w
End Sub

Tested in xl97




.


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
Checkboxes Elaine Excel Discussion (Misc queries) 6 August 20th 09 01:41 AM
Find loop doesn't loop JSnow Excel Discussion (Misc queries) 2 June 24th 09 08:28 PM
Using Checkboxes ppidgursky Excel Discussion (Misc queries) 0 April 7th 09 07:24 PM
checkboxes helpless101 Excel Worksheet Functions 0 April 10th 06 11:54 AM
Checkboxes Randy L Excel Discussion (Misc queries) 3 February 22nd 06 08:09 PM


All times are GMT +1. The time now is 07:00 PM.

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"