I'm needing to add a condition to the following code, but I just can't get the syntax right. I need it to insert checkboxes into column F only when there is data in Column A.
The code in bold is my attempt to add the condition. What am I doing wrong?
Option Explicit
Sub InsertCheckboxes()
Sub Test()
Dim LastRow As Long
LastRow = Cells(Rows.Count, 8).End(xlUp).Row
Dim myBox As CheckBox
Dim myCell As Range
Dim Last As Long
Dim i As Integer
Dim cellRange As Range
Dim cboxLabel As String
Dim linkedColumn As String
Set cellRange = Range("F4:F" & LastRow & "")
linkedColumn = "Z"
cboxLabel = ""
With ActiveSheet
For Each myCell In cellRange
For i = Last To 1 Step -1
If (Cells(i, "A").Value) <> "" Then
With myCell
Set myBox = .Parent.CheckBoxes.Add(Top:=.Top, _
Width:=.Width, Left:=.Left, Height:=.Height)
With myBox
.LinkedCell = linkedColumn & myCell.Row
.Caption = cboxLabel
.Name = "checkbox_" & myCell.Address(0, 0)
.OnAction = "Mixed_State"
End With
.NumberFormat = ";;;"
End With
End If
Next i
Next myCell
End With
End Sub
thanks!!
Bookmarks