Checkbox Macro to Identify the Linked Cell of the Checkbox in Excel 2010

lostitagain

New Member
Joined
Jul 5, 2012
Messages
21
I am attempting to use checkboxes on a worksheet that if checked will increase the value of the cell 3 columns to the right of the linked cell by 10.

I have many (>20) checkboxes on this sheet so I want to write one macro that will identify the linked cell of the checkbox clicked and then update the cell located 3 columns to the right of the linked cell (Range("insert linked cell here").Offset(0,3)).

If the cell was checked and becomes unchecked it should decrease the same cell by 10.

The checkboxes are currently Form controls but I can switch them to activeX if necessary.

any help would be appreciated.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi - hope the below helps
Sub BoxClick()
x = Application.Caller 'The name of the control which started it
Set cb = ActiveSheet.Shapes(x)
stradd = cb.ControlFormat.LinkedCell
If cb.ControlFormat.Value = 1 Then 'Switched on
Range(stradd).Offset(0, 3) = Range(stradd).Offset(0, 3) + 10
Else
Range(stradd).Offset(0, 3) = Range(stradd).Offset(0, 3) + 30
End If

End Sub
 
Upvote 0
Thanks for the reply. Here's the solution I ended up going with:

Code:
Sub CheckBox_Click()
Dim Location As Range
Dim ctrl As Object

Set ctrl = ActiveSheet.Shapes(Application.Caller).OLEFormat.Object
Set Location = Range(ctrl.LinkedCell)

End Sub

That gave me the location of the linked cell and then I am able to use offset and if statements to do anything else I need to the cell which has the value I would like to change.
 
Upvote 0
Thanks for the reply. Here's the solution I ended up going with:

Code:
Sub CheckBox_Click()
Dim Location As Range
Dim ctrl As Object

Set ctrl = ActiveSheet.Shapes(Application.Caller).OLEFormat.Object
Set Location = Range(ctrl.LinkedCell)

End Sub

That gave me the location of the linked cell and then I am able to use offset and if statements to do anything else I need to the cell which has the value I would like to change.

Another way to skin the cat. FWIW.

Code:
Sub ckLink()
With Sheets(1)
For Each objx In .OLEObjects
If TypeName(objx.Object) = "CheckBox" Then
If objx.Object.Value = True Then
Range(objx.LinkedCell).Offset(0, 3) = "Hello"
End If
End If
Next
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,727
Messages
6,174,146
Members
452,547
Latest member
Schilling

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