ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro code to center pasted data in a column (https://www.excelbanter.com/excel-discussion-misc-queries/149428-macro-code-center-pasted-data-column.html)

Rich K.

Macro code to center pasted data in a column
 
Using Excel 2003, I have to add data to a spreadsheet throughout the data by
pasting data from a query. Is the some code to center data in a column
and/or right or left justify as well? I am a novice macro coder so all help
is greatly appreciated.

Don Guillett

Macro code to center pasted data in a column
 
Have you tried recording a macro while doing manually. Then clean up

sub centercol
Columns("E:F").horizontalAlignment = xlCenter
end sub

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 7/9/2007 by Donald B. Guillett
'

'
Columns("E:F").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Rich K." wrote in message
...
Using Excel 2003, I have to add data to a spreadsheet throughout the data
by
pasting data from a query. Is the some code to center data in a column
and/or right or left justify as well? I am a novice macro coder so all
help
is greatly appreciated.



Rich K.

Macro code to center pasted data in a column
 
Thanks - that's what I did - the only problem I had with centering the column
was that it was a shared workbook. Once I took that off, works great,
Thanks for the tips and help


"Don Guillett" wrote:

Have you tried recording a macro while doing manually. Then clean up

sub centercol
Columns("E:F").horizontalAlignment = xlCenter
end sub

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 7/9/2007 by Donald B. Guillett
'

'
Columns("E:F").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Rich K." wrote in message
...
Using Excel 2003, I have to add data to a spreadsheet throughout the data
by
pasting data from a query. Is the some code to center data in a column
and/or right or left justify as well? I am a novice macro coder so all
help
is greatly appreciated.





All times are GMT +1. The time now is 06:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com