Tuesday, 26 May 2020

Text Alignment in Excel VBA

In this tutorial, you will learn about Text Alignment in Excel VBA.  First, we must know that what is the text alignment in Excel and then we will apply this with the help of Excel VBA macros.


So alignment the text in Excel, align text dataset in a cell, “Left, Center, Right” or “Top, Middle, Bottom”. We align the text in Excel as per our dataset requirement.


For aligning option, go to the “Home” tab and search for “Alignment” group, see the image below.





There are two types of text alignment in Excel. Understand this with the help of the below example.


1. Vertical Alignment (Top, Center, Bottom)


2. Horizontal alignment (Left, Center, Right)



Now we will understand these alignment step by step.


     Vertical Alignment (Top, Center, Bottom)


In this alignment, our text data move vertically only, such as bottom to top or top to bottom, three-steps: - Top, Middle, and Bottom.

See image below for Vertical Alignment:-



Horizontal alignment (Left, Center, Right)


Horizontal Alignment: - In this alignment, our text moves “horizontally”, i.e.  From left to right or right to left, with three-steps: - Left, Center, or Right.

See image below for Horizontal Alignment:-





Now with the help of VBA macros I will align the below-given dataset range from “A1: C3”.


See image below:-




Now with the help of VBA macros, I will align the text both ways: - First vertically and horizontally.



1.  Vertical Alignment=Top.


All text has been shifted to top of the cell, see below:-













2. Vertical Alignment=Center


All the text has been shifted to the center of the cell.








3. Vertical Alignment=Bottom


All the text has been shifted to the bottom of the cell





4. Horizontal Alignment = Left


All the text value has been shifted to the extreme left.







5. Horizontal Alignment = Center


See in this image, all text values shifted to the middle of the cell.





6. Horizontal Alignment = Right


See here, the text value shifted to the extreme right of the cell.












So here we learn about 6 types of text alignment in Excel VBA.

I hope you find this article helpful.


Please feel free to put your comments in the below box.



Regards










No comments:

Post a Comment

Featured post

Pivot Tables