Hi All,
I have several checkboxes in a userform
I want to run the same code if any one or several of them is selected
or run another code if anyone of them or several of them deselected.
How can i do this..
Thanks for all the help
Hi All,
I have several checkboxes in a userform
I want to run the same code if any one or several of them is selected
or run another code if anyone of them or several of them deselected.
How can i do this..
Thanks for all the help
Do you mean this ?
Private Sub CheckBox1_Click()
If Me.CheckBox1.Value = True Then
'macro 1
Else
macro2
End If
End Sub
--
Regards Ron de Bruin
http://www.rondebruin.nl
"Soniya" <[email protected]> wrote in message news:[email protected]...
> Hi All,
>
> I have several checkboxes in a userform
>
> I want to run the same code if any one or several of them is selected
> or run another code if anyone of them or several of them deselected.
>
> How can i do this..
>
> Thanks for all the help
>
in that case i have to write code for each checkbox click or change
event. in my case any check box in the form i have to call the same
macro
If you have many then see
http://www.j-walk.com/ss/excel/tips/tip44.htm
--
Regards Ron de Bruin
http://www.rondebruin.nl
"Soniya" <[email protected]> wrote in message news:[email protected]...
> in that case i have to write code for each checkbox click or change
> event. in my case any check box in the form i have to call the same
> macro
>
Soniya,
To cover more than one checkbox, do the following:
(a) In your Userform module:
Option Explicit
Dim Buttons() As New ChkClass
Private Sub UserForm_Initialize()
Dim n As Integer
Dim ctl As Control
n = 1
For Each ctl In Me.Controls
If ctl.Name = "CheckBox" & n Then
ReDim Preserve Buttons(1 To n)
Set Buttons(n).ButtonGroup = ctl
n = n + 1
End If
Next
End Sub
(b) Create a Class module and name it "Chkclass"; then put :
Public WithEvents ButtonGroup As MsForms.CheckBox
Sub ButtonGroup_Click()
MsgBox ButtonGroup.Name
Call TriggerCode
End Sub
(c) finally, put in a general module the code you want to run:
Sub TriggerCode()
<Code ... >
End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks