ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Multiple Check Boxes calling same macro (https://www.excelbanter.com/excel-programming/393103-multiple-check-boxes-calling-same-macro.html)

Paul

Multiple Check Boxes calling same macro
 
I have a list of items each with a named check box.

All the check boxes run the same priece of code with only one difference
each time, being related to data on the line being amended.

When a check box is changed, how do I find out programmatically which check
box has been clicked ?

I want to avoid having 50 plus macros to deal with each check box separately.

Bob Phillips

Multiple Check Boxes calling same macro
 
Public Sub Test()
Select Case Application.Caller
Case "Check Box1"
MsgBox "1 called"
Case "Check Box 2"
MsgBox "2 called"
'etc.
End Select
End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Paul" wrote in message
...
I have a list of items each with a named check box.

All the check boxes run the same priece of code with only one difference
each time, being related to data on the line being amended.

When a check box is changed, how do I find out programmatically which
check
box has been clicked ?

I want to avoid having 50 plus macros to deal with each check box
separately.




Paul

Multiple Check Boxes calling same macro
 
Fast and fantastic answer !!

"Bob Phillips" wrote:

Public Sub Test()
Select Case Application.Caller
Case "Check Box1"
MsgBox "1 called"
Case "Check Box 2"
MsgBox "2 called"
'etc.
End Select
End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Paul" wrote in message
...
I have a list of items each with a named check box.

All the check boxes run the same priece of code with only one difference
each time, being related to data on the line being amended.

When a check box is changed, how do I find out programmatically which
check
box has been clicked ?

I want to avoid having 50 plus macros to deal with each check box
separately.





Incidental

Multiple Check Boxes calling same macro
 
Hi Paul

You could try something like the code below which will work but will
lead to still haveing more code than you need i would recommend you
check out the following link which gives a great example of using a
class module to do the work for you.

http://j-walk.com/ss/excel/tips/tip44.htm

Option Explicit
Dim i As Integer
Dim Ctrl As MSForms.Control

Private Sub CheckBox1_Click()
i = 1
DoYourStuff
End Sub
Private Sub CheckBox2_Click()
i = 2
DoYourStuff
End Sub
Private Sub CheckBox3_Click()
i = 3
DoYourStuff
End Sub

Sub DoYourStuff()

Set Ctrl = UserForm1.Controls("CheckBox" & i)

'from here you can refer to the clicked control
'using " Ctrl "

MsgBox Ctrl.Name

End Sub

Hope this helps

S



All times are GMT +1. The time now is 05:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com