Excel VBA, Vertical Alignment
In this article I will explain the different vertical alignment formattings applicable to cells and ranges. I have also provided the VBA code required to apply them.
Jump To:
Contents
Top, xlTop:
The following code will top align the text in cell “A1”:
Range("A1").VerticalAlignment = xlTop
Result:
Center, xlCenter:
The following code will center align the text in cell “A1” in the vertical direction:
Range("A1").VerticalAlignment = xlCenter
Result:
Bottom, xlBottom:
The following code will bottom align the text in cell “A1”:
Range("A1").VerticalAlignment = xlBottom
Result:
Justify, xlJustify:
The vertical justify formatting will be apparent when you have a 90 deg orientation and the text wrap is checked. The following code applies the verticle justify formatting to cell “A1”:
Range("A1").VerticalAlignment = xlJustify
Before:
After:
Distributed, xlDistributed:
The vertical distributed formatting will be apparent when you have a 90 deg orientation and the text wrap is checked. The following code applies the vertical distributed formatting to cell “A1”:
Range("A1").VerticalAlignment = xlDistributed
Before:
After:
See also:
- Excel VBA Formatting Cells and Ranges Using the Macro Recorder
- VBA Excel, Alignment
- Excel VBA, Set Vertical Alignment (Sample Code)
- Excel VBA, Get Vertical Alignment (Sample Code)
If you need assistance with your code, or you are looking for a VBA programmer to hire feel free to contact me. Also please visit my website www.software-solutions-online.com