Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command to Left Align Data in Excel

Status
Not open for further replies.

txmed

Programmer
Mar 23, 2006
65
0
0
US
Greetings! I've created a procedure that dumps data into an excel spreadsheet. I am using the CreateObject function to create the spreadsheet at run-time. After I've written all of the data I'm using the EntireColumn.AutoFit() function to autofit all of the columns.

Does anyone know the command for me to adjust all of the columns to left align? I've searched the web for a while but haven't been able to find here.

Here is some of my code.

Code:
Dim xlsApp As Object
Dim xlsBook As Object
Dim xlsSheet As Object

xlsApp = CreateObject("Excel.Application")
xlsBook = xlsApp.Workbooks.Add
xlsSheet = xlsBook.Worksheets(1)

' other code here.

xlsSheet.Cells.EntireColumn.AutoFit()
[COLOR=red]
' place code here to set left align.
[/color]

Thanks in advanced for your help.

(txmed)
 
Code:
xlsSheet.Cells.HorizontalAlignment = xlLeft

-I hate Microsoft!
-Forever and always forward.
 
Sorry I'm so use to doing that in Excel I forgot it will not know what xlLeft is.

Code:
ActiveSheet.Cells.HorizontalAlignment = -4131

-I hate Microsoft!
-Forever and always forward.
 
Sorwen,

Thank you for the sample code. Since I am using late-binding, I'm going to have to use this code:

Code:
ActiveSheet.Cells.HorizontalAlignment = -4131

As soon as I get a chance I will try it out. Thanks for your help!

(txmed)
 
Sorwen, the code you gave me worked. Thank you so much!

(txmed)
 
NP. I'm glad.

-I hate Microsoft!
-Forever and always forward.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top