By: Lutfor Rahman Shimanto

In reply to Tim.

Hello TIM

Thanks for reaching out and sharing your query. You want an Excel VBA code that works perfectly for multiple columns and rows of checkboxes. I am presenting an enhanced VBA sub-procedure that may help you.

OUTPUT OVERVIEW:

Enhanced Excel VBA Code:

Sub AlignCheckbox()

Dim xRg As Range
Dim chkBox As OLEObject
Dim chkFBox As CheckBox
Dim cell As Range
Dim cellWidth As Double
Dim cellHeight As Double

On Error Resume Next
Application.ScreenUpdating = False

For Each chkBox In ActiveSheet.OLEObjects
If TypeName(chkBox.Object) = "CheckBox" Then
Set xRg = chkBox.TopLeftCell
With xRg
cellWidth = .Width
cellHeight = .Height
chkBox.Width = cellWidth * 2 / 3
chkBox.Left = .Left + (cellWidth - chkBox.Width) / 2
chkBox.Top = .Top + (cellHeight - chkBox.Height) / 2
End With
End If
Next

For Each chkFBox In ActiveSheet.CheckBoxes
Set xRg = chkFBox.TopLeftCell
With xRg
cellWidth = .Width
cellHeight = .Height
chkFBox.Width = cellWidth * 2 / 3
chkFBox.Height = cellHeight
chkFBox.Left = .Left + (cellWidth - chkFBox.Width) / 2
chkFBox.Top = .Top + (cellHeight - chkFBox.Height) / 2
End With
Next

Application.ScreenUpdating = True

End Sub

Hopefully, the sub-procedure will reduce your hassle. Good luck.

Regards
Lutfor Rahman Shimanto
Excel & VBA Developer
ExcelDemy