How to auto-center checkbox in cell in Excel?
While inserting check boxes in cells in Excel, you might notice that it is hard to arrange all checkboxes orderly as the left screenshot shown. Actually, you can move all check boxes to cell center to keep them in order neatly. Method in this article can help you.
Recommended Productivity Tools for Excel
Office Tab: Bring powerful tabs to Office (include Excel), just like Chrome, Safari, Firefox and Internet Explorer. Save you half the time, and reduce thousands of mouse clicks for you. 30-day Unlimited Free Trial
Kutools for Excel: Save 71% of your time and solve 82% Excel problems for you. 300+ advanced tools designed for 1500+ work scenario, make Excel much easy and increase productivity immediately.60-day Unlimited Free Trial
To automatically center all checkboxes in cells in a current worksheet, please do as follows.
1. In the worksheet, you need to auto-center all checkboxes, press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.
2. In the Microsoft Visual Basic for Applications window, please click Insert > Module. Then copy and paste VBA code into the code window.
VBA code: Automatically center all checkboxes in cells
Sub CenterCheckbox () Dim xRg As Range Dim chkBox As OLEObject Dim chkFBox As CheckBox On Error Resume Next Application.ScreenUpdating = False For Each chkBox In ActiveSheet.OLEObjects If TypeName(chkBox.Object) = "CheckBox" Then Set xRg = chkBox.TopLeftCell chkBox.Width = xRg.Width * 2 / 3 chkBox.Height = xRg.Height chkBox.Left = xRg.Left + (xRg.Width - chkBox.Width) / 2 chkBox.Top = xRg.Top + (xRg.Height - chkBox.Height) / 2 End If Next For Each chkFBox In ActiveSheet.CheckBoxes Set xRg = chkFBox.TopLeftCell chkFBox.Width = xRg.Width * 2 / 3 chkFBox.Height = xRg.Height chkFBox.Left = xRg.Left + (xRg.Width - chkFBox.Width) / 2 chkFBox.Top = xRg.Top + (xRg.Height - chkFBox.Height) / 2 Next Application.ScreenUpdating = True End Sub
3. Press the F5 key. Then all checkboxes are moved into the center of the cells immediately as below screenshot shown.
Note: This VBA code can be applied to both CheckBox (ActiveX Control) and CheckBox (Form Control).
- How to create a drop down list with multiple checkboxes in Excel?
- How to change a specified cell value or color when checkbox is checked in Excel?
- How to highlight cell or row with checkbox in Excel?
- How to make checkbox checked based on cell value in Excel?