#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Checkboxes

No sense doing two loops

Dim ctrl As Control
Dim inct As Long
icnt = 0
For Each ctrl In UserForm2.Controls
If TypeOf ctrl Is MSForms.CheckBox Then
ActiveCell.offset(icnt,1).Value = ctrl.caption
if ctrl.Value then
ActiveCell.offset(icnt,0).Value = "Yes"
else
ActiveCell.offst(icnt,0).Value = "No"
end if
End if
icnt = icnt + 1
Next
'MsgBox "there are " & icnt & " checboxes"


If you use Thomas's approach, you will get icnt cells with "yes" in them -
not sure that will tell you much unless you want to count the cells that
contain yes. (However, it does reflect your code). This way, the cells
will correspond to the tabindex property of the checkboxes relative to each
other.


--
Regards,
Tom Ogilvy


"Shamsul" wrote in message
...
Hi

I'am trying to write code for a number of Checkboxes in a
Userform.

I don't want to repeat the code for each checkbox. I tried
to use the code below, but it didn't work. Can someone
please advise.

Dim ctrl As Control
Dim inct As Long
Dim X As Long
icnt = 0
For Each ctrl In UserForm2.Controls
If TypeOf ctrl Is MSForms.CheckBox Then
icnt = icnt + 1
End If
Next
MsgBox "there are " & icnt & " checboxes"

Range("S3").Select
For X = 1 To icnt
If CheckBoxX = True Then
ActiveCell.FormulaR1C1 = "YES"
ActiveCell.Offset.Select
End If
Next X



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 stretch Excel Worksheet Functions 4 September 14th 07 12:36 PM
Checkboxes Randy L Excel Discussion (Misc queries) 3 February 22nd 06 08:09 PM
CheckBoxes Laur Excel Discussion (Misc queries) 2 March 22nd 05 07:40 PM
Checkboxes Es Excel Discussion (Misc queries) 1 March 14th 05 02:07 PM
Checkboxes chuck Excel Discussion (Misc queries) 1 January 25th 05 03:48 AM


All times are GMT +1. The time now is 02:20 PM.

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

About Us

"It's about Microsoft Excel"