Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default CheckBox Change Event

Hi All,

I have 20 Check boxes Named C100 thru C120

for all the checkboxes i have:

Private Sub C100_change()
Macro1
End Sub

thru .....


Private Sub C120_change()
Macro1
End Sub

instead of repeating this afor all 20 checkboxes is there any other way
to do this?

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default CheckBox Change Event

Soniya,

there is no concept of control arrays in VBA as there is in VB, but it can
be simulated.

Create a class module, and call it cControlArray, and add this code

Option Explicit

Public WithEvents CheckboxGroup As msforms.CheckBox

Private Sub CheckboxGroup_Click()
MsgBox CheckboxGroup.Caption & _
IIf(CheckboxGroup.Value, " has been set", " has been unset")
End Sub


The code in the click event should be substitued for your real code, but is
used to show you how to access properties of the chosen checkbox.

The add a normal code module and add this code

Option Explicit

Dim aryCBs() As New cControlArray

Sub ShowForm()
UserForm1.Show
End Sub

This setsup the pseudo-control array with your form checkboxes, and then
shows the form. Change Userform1 to your form name.

and in the userform add this code

Private Sub UserForm_Initialize()
Dim cCBs As Integer
Dim ctl As Control

cCBs = 0
For Each ctl In Me.Controls
If TypeName(ctl) = "CheckBox" Then
cCBs = cCBs + 1
ReDim Preserve aryCBs(1 To cCBs)
Set aryCBs(cCBs).CheckboxGroup = ctl
End If
Next ctl

End Sub

--
HTH

Bob Phillips

"Soniya" wrote in message
ups.com...
Hi All,

I have 20 Check boxes Named C100 thru C120

for all the checkboxes i have:

Private Sub C100_change()
Macro1
End Sub

thru .....


Private Sub C120_change()
Macro1
End Sub

instead of repeating this afor all 20 checkboxes is there any other way
to do this?

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default CheckBox Change Event

Are these checkboxes on a worksheet?

If yes, you could replace them with checkboxes from the forms toolbar and assign
each checkbox the same macro.

Inside your macro, you can determine which checkbox is being checked:

Option Explicit
Sub macro1()
Dim CBX As CheckBox
Set CBX = ActiveSheet.CheckBoxes(Application.Caller)
With CBX
MsgBox .Name & vbLf & .Value & vbLf & .TopLeftCell.Address
End With
End Sub



Soniya wrote:

Hi All,

I have 20 Check boxes Named C100 thru C120

for all the checkboxes i have:

Private Sub C100_change()
Macro1
End Sub

thru .....

Private Sub C120_change()
Macro1
End Sub

instead of repeating this afor all 20 checkboxes is there any other way
to do this?

Thanks


--

Dave Peterson
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 Event BHatMJ Excel Discussion (Misc queries) 2 May 16th 08 06:14 PM
Click Checkbox Event Montana DOJ Help Desk Excel Programming 4 November 11th 04 04:25 AM
Trigger an event on Checkbox change James Geniti Excel Programming 0 September 1st 04 09:24 PM
Trigger an event on Checkbox change James[_28_] Excel Programming 2 September 1st 04 08:31 PM
CheckBox Event devin Excel Programming 2 January 29th 04 05:59 PM


All times are GMT +1. The time now is 03:24 AM.

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"