Automatically update cell link of activex checkboxes

Empirer

New Member
Joined
Oct 15, 2020
Messages
11
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

Would like your help on a vba code that would update the cell link of activex checkboxes for each row.
I currently have 3 checkboxes in AL2, each of the checkboxes link to a different column; first checkbox links to column AN2, second links to AO2, third links to AP2.
When copying down the checkboxes up to row 100, the cell links remains linked to row 2.

Kindly assist in providing a vba to update these cell links.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
have a go at this

VBA Code:
Sub LoopThroughCheckboxes()

'Create variable
Dim chkBox As CheckBox
Dim r As Range, r2 As Range

'Loop through each check box on active sheet
For Each chkBox In ActiveSheet.CheckBoxes

    With chkBox
        Set r = Range(.TopLeftCell.Address)
        Set r2 = Range(.LinkedCell)
        .LinkedCell = r.Offset(, r2.Column - r.Column).Address
       
    End With
Next chkBox

End Sub
 
Upvote 0
have a go at this

VBA Code:
Sub LoopThroughCheckboxes()

'Create variable
Dim chkBox As CheckBox
Dim r As Range, r2 As Range

'Loop through each check box on active sheet
For Each chkBox In ActiveSheet.CheckBoxes

    With chkBox
        Set r = Range(.TopLeftCell.Address)
        Set r2 = Range(.LinkedCell)
        .LinkedCell = r.Offset(, r2.Column - r.Column).Address
      
    End With
Next chkBox

End Sub
Unfortunately, this code doesn't work.

Maybe the issue is that the checkboxes in the subsequent rows are considered to be the same as in row 2. So whenever I tick a box in row 3, it will also update the checkbox in row 2 and all the other rows. It does not see them as individual checkboxes.
 
Upvote 0
the code loops through all checkboxes on the active worksheet, checks their TopLeftCell location and adjusts the LinkedCell to the row of the TopLeftCell and the column of the LinkedCell (eventhough the linked cell's row is incorrect we use the column).

Can you post a picture of your worksheet showing the position of the checkboxes?
 
Upvote 0
Crystalyzer's code works, just overlooked that the check boxes are ActiveX controls
Try this
VBA Code:
Sub LoopThroughCheckboxes()
'Create variable
Dim chkbox As Object
Dim r As Range, r2 As Range
'Loop through each check box on active sheet
For Each chkbox In ActiveSheet.OLEObjects
    If TypeName(chkbox.Object) = "CheckBox" Then
        With chkbox
            Set r = Range(.TopLeftCell.Address)
            Set r2 = Range(.LinkedCell)
            .LinkedCell = r.Offset(, r2.Column - r.Column).Address
        End With
    End If
Next chkbox
End Sub
 
Upvote 0
Crystalyzer's code works, just overlooked that the check boxes are ActiveX controls
Try this
VBA Code:
Sub LoopThroughCheckboxes()
'Create variable
Dim chkbox As Object
Dim r As Range, r2 As Range
'Loop through each check box on active sheet
For Each chkbox In ActiveSheet.OLEObjects
    If TypeName(chkbox.Object) = "CheckBox" Then
        With chkbox
            Set r = Range(.TopLeftCell.Address)
            Set r2 = Range(.LinkedCell)
            .LinkedCell = r.Offset(, r2.Column - r.Column).Address
        End With
    End If
Next chkbox
End Sub

Thanks for the reply, however it still didnt work. Same issue like before, whenever a checkbox is ticked, it will update all the other checkboxes as well and the linked cell remains in the second row only.
 

Attachments

  • unnamed.jpg
    unnamed.jpg
    46.4 KB · Views: 32
Upvote 0
Works for me.
Can troubleshoot a sheet but not a picture.

Merged cells ?
 
Last edited:
Upvote 0
Works for me.
Can troubleshoot a sheet but not a picture.

Merged cells ?

I'm unable to add in activex checkboxes in the minisheet, checkboxes were originally in AL:
FIG WFS Offline QC Tracker.xlsm
ALAMANAOAP
1Inline Quality Control TrendAnalyst Control CommentsFilter Checkbox CornerstoneFilter Checkbox DocsFilter Checkbox Other
2TRUEFALSEFALSE
3
Sheet1
 
Upvote 0
You could share a file from Google Drive, One Drive, Dropbox or the one I use
box.com, it's free and easy.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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