Excel VBA Horizontal Alignment and Vertical Alignment - learnit

Home Top Ad

Post Top Ad

Wednesday, April 14, 2021

Excel VBA Horizontal Alignment and Vertical Alignment

Excel VBA Horizontal Alignment and Vertical Alignment

Excel VBA Horizontal Alignment and Vertical Alignment

What is Excel VBA?

VBA stands for Visual Basic for Applications. Excel VBA is Microsoft’s programming language for Excel and all the other Microsoft Office programs, like Word and PowerPoint. The Office suite programs all share a common programming language.


Why Use Excel VBA

While users cannot directly manipulate the main Excel software through VBA, they can, however, master the art of making macros to optimize their time in Excel. There are two ways to make Excel macros.


The first method is to use the Macro Recorder. After activating the recorder, Excel will record all the steps a user makes and save it as a “process” known as a macro. When the user ends the recorder, this macro is saved and can be assigned to a button that will run the exact same process again when clicked. This method is relatively simple and requires no inherent knowledge of the VBA code. This method will work for simple processes.


However, the downfall of this method is that it is not very customizable, and the macro will mimic the user’s input exactly. By default, recorder macros also use absolute referencing instead of relative referencing. IKt means that macros made in this way are very hard to use with variables processe.


Horizontal Alignment

This property cell format property returns or sets a variant value that represents the horizontal alignment for the specified object. Returned or set constants can be: xlGeneral, xlCenter, xlDistributed, xlJustify, xlLeft, xlRight, xlFill, xlCenterAcrossSelection.


Example

Sub Horizontalalgnemtnt()
Range("B1:B20").HorizontalAlignment=xlLeft
Range("B1:B20").HorizontalAlignment=xlCenter
Range("B1:B20").HorizontalAlignment=xlRight
End Sub

Vertical Alignment

In this article I will explain the different vertical alignment formatting applicable to cells and ranges. I have also provided the VBA code required to apply them. Returned or Set Constants Can Be:Top,Xtop,Center,xlClenter,Bottom,XlBottom,Justify,xUusrtify,Distributed,xlDistributed.

Sub VerticalAlignment()
Range("A1:A20").verticalAlignment=xlTop
Range("A1:A20").verticalAlignment=xlCenter
Range("A1:A20").verticalAlignment=xlBottom
End Sub

Please Watching My Video is Below

No comments:

Post a Comment

Post Top Ad