简体   繁体   中英

excel vba macro assign checkboxes to cells in different sheet

I am trying to run a macro that will assign all checkboxes in a sheet to the same cell in an other sheet. But i am not good in vba (never done it actually, so read not good as... ). I do understand some progamming so this is what i came up with so far, but i am stuck:

    Sub LinkCheckBoxes()
Dim chk As CheckBox

For Each chk In ActiveSheet.CheckBoxes
    With chk
        .LinkedCell = Worksheets("data").Address
    End With

Next chk

End Sub

This does not work and I am unable to find the correct code to make it work. It only has to run once, to set the links as they are now unlinked.

(if it runs it will take care of 500 checkboxes for me...)

Thanks

If you wish to link them to the cells that they are over, but on a different sheet:

Sub LinkCheckBoxes()
   Dim chk As CheckBox

   For Each chk In ActiveSheet.CheckBoxes
      chk.LinkedCell = "Data!" & chk.Topleftcell.address
   Next chk

End Sub

Note that this uses the cell under the top left corner of the checkbox shape, which may not be the same as the cell the actual checkbox appears to be over.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM