MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Cell Justification Using a Macro (VBA)

Posted by Peter on January 07, 2002 2:50 PM

Anyone know how to left justify (assume they were right justified before) a range of cells in a spreadsheet by using only a macro? Many thanks.

Posted by Jacob on January 07, 2002 3:24 PM


Try this

Range("A1:C100).Select 'Modify as needed
With Selection
.HorizontalAlignment = xlLeft
End With


Posted by Scroop on January 08, 2002 1:26 AM

If you want all selected cells to be left aligned:-

Selection.HorizontalAlignment = xlLeft

If you want to change the alignment only for selected cells that are right aligned (to left alignment) :-

Dim cell As Range
For Each cell In Selection
If cell.HorizontalAlignment = xlRight Then cell.HorizontalAlignment = xlLeft