vba advanced
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » VBA Advanced

VBA Advanced

resolvedResolved · Medium Priority · Version 2003

replyReply Thu 9 Dec 2010, 15:49Delegate Richard said...

Richard has attended:
Excel VBA Advanced course

VBA Advanced

I have developed a userform which has a number of checkboxes (48), named checkbox1 to checkbox48. Is there any way these can be put into a collection of checkboxes, so if I need to do something to them, then can all be changed, or for example, every even one or every 12th one (they represent 4 years).

For upcoming training course dates see: Pricing & availability

replyReply Wed 15 Dec 2010, 15:22Trainer Anthony said...

RE: VBA Advanced

Hi Richard, thanks for your query. There are a number ways you could do this, probably the most efficient would be to use an array, particularly if the check boxes already exist on the form. Here is a basic walkthrough of what I would do. Adapt as you see fit.

Declare the array at the top of the module as so:

Private chkArray(48) as Checkbox

Initialise it:

Set chkArray(0) = chkFirst
Set chkArray(1) = chkSecond
...
Set chkArray(48) = chkLast

...and then use it in this fashion:

Dim intLoop as Integer
Dim intCount as Integer
intCount = 0
For intLoop = 0 to 31
If chkArray(intLoop).Value = True Then
intCount = intCount + 1
End If
Next intLoop

MsgBox "Selected: " & intCount

You should then be able to adapt this select and deselect particular checkboxes, use "Step 2" to select every second one, and so on.

Hope this helps,

Anthony

Tue 21 Dec 2010: Automatically marked as resolved.

 

Please browse our web site to find out more about
excel computer training and other Microsoft training courses.

Excel tip:

Separate the year from a date

To separate the year from a date use the =year() function, eg a date is in cell A1 and in A2 you wish to display the year enter the function =year(A1)

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard