I have added a checkbox to my spreadsheet, I would like to not have the checkbox appear unless there is data in the referenced cell...
Here is the code I used
ub AddCheckBoxToCell(Ref_Cell As Range)
Dim ChkBox As CheckBox
Dim N As Double
With Ref_Cell.Cells(1, 1)
refLeft = .Left
refTop = .Top
refHeight = .Height
End With
Set ChkBox = ActiveSheet.CheckBoxes.Add(10, 10, 15, 12)
N = (refHeight - ChkBox.Height) / 2#
With ChkBox
.Caption = ""
.Top = refTop + N
.Left = refLeft
.OnAction = ""
End With
End Sub
Sub AddCheckBoxes()
Dim BoxCol As Variant
Dim CtrlCol As Variant
Dim LastRow As Long
Dim R As Long
Dim StartRow As Long
BoxCol = "B" 'Column where Check Box is inserted
CtrlCol = "A" 'Column that controls if Check Box is inserted
StartRow = 1
LastRow = Cells(Rows.Count, CtrlCol).End(xlUp).Row
For R = StartRow To LastRow
If Cells(R, CtrlCol) <> "" Then
AddCheckBoxToCell Cells(R, BoxCol)
End If
Next R
End Sub
Bookmarks