sashapixie
Board Regular
- Joined
- Aug 29, 2013
- Messages
- 71
- Office Version
- 365
- Platform
- Windows
I have the code below to input check boxes and link them to the cells they are located in, I want to change to the range to a dynamic range for e.g
If cell B3 <> "" input check boxes in to columns J3:R3 and also I want to align the check boxes to be in the centre of the cells.
Option Explicit
Sub addCBX()
Dim myCBX As CheckBox
Dim myCell As Range
With ActiveSheet
.CheckBoxes.Delete 'nice for testing
For Each myCell In ActiveSheet.Range("J1:R1").Cells
With myCell
Set myCBX = .Parent.CheckBoxes.Add _
(Top:=.Top, Width:=.Width, _
Left:=.Left, Height:=.Height)
With myCBX
.LinkedCell = myCell.Address(external:=True)
.Caption = "" 'or whatever you want
'.Name = "CBX_" & myCell.Address(0, 0)
End With
.NumberFormat = ";;;"
End With
Next myCell
End With
End Sub
I am quite new to VBA, and have been struggling for a while, I found the code online which works, i am just struggling on where I would make the amendments and how to write them.
Any help would be appreciated.
Thanks
If cell B3 <> "" input check boxes in to columns J3:R3 and also I want to align the check boxes to be in the centre of the cells.
Option Explicit
Sub addCBX()
Dim myCBX As CheckBox
Dim myCell As Range
With ActiveSheet
.CheckBoxes.Delete 'nice for testing
For Each myCell In ActiveSheet.Range("J1:R1").Cells
With myCell
Set myCBX = .Parent.CheckBoxes.Add _
(Top:=.Top, Width:=.Width, _
Left:=.Left, Height:=.Height)
With myCBX
.LinkedCell = myCell.Address(external:=True)
.Caption = "" 'or whatever you want
'.Name = "CBX_" & myCell.Address(0, 0)
End With
.NumberFormat = ";;;"
End With
Next myCell
End With
End Sub
I am quite new to VBA, and have been struggling for a while, I found the code online which works, i am just struggling on where I would make the amendments and how to write them.
Any help would be appreciated.
Thanks