Archive of Mr Excel Message Board


Back to Excel VBA archive index
Back to archive home

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.

Check out our Excel VBA Resources

Re: Cell Justification Using a Macro (VBA)

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

Try this

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

HTH
Jacob


Re: Cell Justification Using a Macro (VBA)

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
Next



This archive is from the original message board at www.MrExcel.com.
All contents © 1998-2004 MrExcel.com.
Visit our online store to buy searchable CD's with thousands of VBA and Excel answers.
Microsoft Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.