Checkbox Number

texasalynn

Well-known Member
Joined
May 19, 2002
Messages
8,458
I've almost got this but haven't found a way to get a checkbox (form type, not ActiveX) number. I have too many and want to avoid putting in those. Here is a sample of my current code. So the reference CheckBox1, I would like to have it be automatically determined so that I can use a variable in my code. Then I can make one generic code to work with each checkbox.

Code:
Option Explicit
Public SRC As String
Private Sub CheckBox1_Click()
Dim i As Variant
    SRC = ActiveSheet.CodeName & "." & Right(CheckBox1.Name, Len(CheckBox1.Name) - 8)
    ActiveCell.Offset(0, 4) = SRC
    i = ActiveCell.Address
    If i = True Then
        Call Chkbx
    End If
    If i = False Then
        Call RemoveLine
        Range(i).Offset(0, 4).Clear
    End If
End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
If you are using Forms controls you seriously need to look at Application.Caller which will give you the name of the control that has triggered the code.

If you are having problems using Application.Caller can you tell us what they are? Error messages? Incorrect results? etc
 
Upvote 0
I've almost got this but haven't found a way to get a checkbox (form type, not ActiveX) number. I have too many and want to avoid putting in those. Here is a sample of my current code. So the reference CheckBox1, I would like to have it be automatically determined so that I can use a variable in my code. Then I can make one generic code to work with each checkbox.
You say your checkbox is a Form type checkbox, but the name you are referring to it by (CheckBox1) is not a name that would normally be associated with a Form control, rather, it is the default name given to the first ActiveX checkbox that would be placed. Did you deliberately renamed the control from Check Box 1 (with the spaces as shown) to CheckBox1. If not, I find it hard to believe that your checkbox is not an ActiveX control. Let's check to be sure... right click what you are calling CheckBox1 and tell us if "Edit Text" and "Assign Macro" are in the popup menu that appears.
 
Upvote 0
Rick - the box does not have edit text nor assign macro. I just realized this is not a form control check box but an activex. I have both types on each sheet and forgot the checkboxes I am working on are the activex type. Sorry about that.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top