Alignment property of checkbox control is used to specify the position of a checkbox control in Excel VBA. It sets an integer value. The possible values are 0(Left side of a control) or 1(Right side of a control).
Checkbox_Alignment_Property – Syntax
Please find the below syntax of Checkbox control Alignment Property in Excel VBA.
CheckboxName.Alignment=0 (fmAlignmentLeft )
Or
CheckboxName.Alignment=1 (fmAlignmentRight )
Where CheckboxName represents the Checkbox object. In the above syntax we are using ‘Alignment’ property of Checkbox object to set the alignment of Checkbox control.
Checkbox_Alignment_Property – Explanation & Example
Here is the example for Checkbox control Alignment_Property. It will take you through how to set alignment property of Checkbox control property using Excel VBA. Here you can find or see how we are using ‘Alignment’ property of Checkbox manually or using code.
Checkbox_Alignment_Property: Change Manually
Please find the following details how we are changing manually ‘Alignment’ property of Checkbox property.
- Go To Developer Tab and then click Visual Basic from the Code or Press Alt+F11.
- Go To Insert Menu, Click UserForm. Please find the screenshot for the same.
- Drag a Checkbox on the Userform from the Toolbox.
- Right click on the List box. Click on properties from the available list.
- Now you can find the properties window of Checkbox on the screen. Please find the screenshot for the same.
- On the left side find ‘Alignment’ property from the available List Box properties.
- On the right side you can see the two available options. i.e.
- You can choose any one from the available options. For example, I have choosen ‘0 – fmAlignmentLeft’. This means Checkbox alignment is towards left. You can see same in the screen shot for your understand.
- You can choose ‘1 – fmAlignmentRight’ from the available options. This means Checkbox alignment is towards right side. You can see same in the screen shot for your understand.
- Go To Developer Tab and then click Visual Basic from the Code or Press Alt+F11.
- Go To Insert Menu, Click UserForm. Please find the screenshot for the same.
- Drag a Checkbox on the Userform from the Toolbox. Please find the screenshot for the same.
- Double Click on the UserForm, and select the Userform event as shown in the below screen shot.
- Now can see the following code in the module.
- Now, add the following example code1 or code2 or code3 to the in between above event procedure.
- Now, Press ‘F5’ to see the following Output.
- Now, Press ‘F5’ to see the following Output.
I. 0 – fmAlignmentLeft
II. 1 – fmAlignmentRight
Checkbox_Alignment_Property: Change Using Code
Please find the following details how we are changing Alignment of Checkbox property with using Excel VBA code.
Private Sub UserForm_Initialize() End Sub
Example Code 1:
Here is the example and output when we set column count property to ‘0’. This means it will display all columns in a Checkbox.
'Alignment Property of Checkbox Control Private Sub UserForm_Initialize() 'The below statement specifies the checkbox position CheckBox1.Alignment = fmAlignmentLeft End Sub
Or
Private Sub UserForm_Initialize() 'The below statement specifies the checkbox position CheckBox1.Alignment = 0 End Sub
Output: If Alignment =0 or fmAlignmentLeft
Please find the below output when we set Alignment property value is 0. It is shown in the following Screen Shot.
Example Code 2:
Here is the example and output when we set column count property to ‘1’. This means it will display all columns in a Checkbox.
'Alignment Property of Checkbox Control Private Sub UserForm_Initialize() 'The below statement specifies the checkbox position CheckBox1.Alignment = fmAlignmentRight End Sub
Or
Private Sub UserForm_Initialize() 'The below statement specifies the checkbox position CheckBox1.Alignment = 1 End Sub
Output: If Alignment =1 or fmAlignmentRight
Please find the below output when we set Alignment property value is 1. It is shown in the following Screen Shot.
A Powerful & Multi-purpose Templates for project management. Now seamlessly manage your projects, tasks, meetings, presentations, teams, customers, stakeholders and time. This page describes all the amazing new features and options that come with our premium templates.
LIMITED TIME OFFER
Advanced Project Planning Templates
Excel Templates
120+ Project Management Templates Pack
Excel | PowerPoint | Word
ULTIMATE RESOURCE MANAGEMENT TEMPLATE
Excel Template
50+ Essential Project Management Templates
Excel | PowerPoint | Word
Project Portfolio Management Templates
Excel | PowerPoint Templates
50+ Excel Project Management Templates
Excel Templates