ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem with xlCenterAcrossSelection (https://www.excelbanter.com/excel-programming/332405-problem-xlcenteracrossselection.html)

Sanj

Problem with xlCenterAcrossSelection
 
I am using the following piece of code to center a title across a changing
range, where intMaxRow (I know the wrong row, column reference) is the last
column.

..Range("A2").Resize(1, intMaxRow).HorizontalAlignment = _
xlCenterAcrossSelection

The problem is that it does not reset the range, it only takes the last
greatest width. For example Previously intMaxRow = 8 and I reset it to
intMaxRow = 4, it will still center it across the 8 rather than the 4.

Any thoughts

Jim Cone

Problem with xlCenterAcrossSelection
 
Sanj,

Because you are not changing the settings.
Each cell in cols 1 to 8 is CenterAcross.
Setting cols 1 to 4 to CenterAcross is just repeating the existing
settings for those cells.
You can change the settings for cols 5 to 8 back to "General" to
leave columns 1 to 4 as CenterAcross.

Jim Cone
San Francisco, USA


"Sanj" wrote in message
...
I am using the following piece of code to center a title across a changing
range, where intMaxRow (I know the wrong row, column reference) is the last
column.

..Range("A2").Resize(1, intMaxRow).HorizontalAlignment = _
xlCenterAcrossSelection

The problem is that it does not reset the range, it only takes the last
greatest width. For example Previously intMaxRow = 8 and I reset it to
intMaxRow = 4, it will still center it across the 8 rather than the 4.
Any thoughts

Tom Ogilvy

Problem with xlCenterAcrossSelection
 
Before changing intMaxRow, try resetting the old range's HorizontalAlignment
to something else. Then try centering across.

--
Regards,
Tom Ogilvy

"Sanj" wrote in message
...
I am using the following piece of code to center a title across a changing
range, where intMaxRow (I know the wrong row, column reference) is the

last
column.

.Range("A2").Resize(1, intMaxRow).HorizontalAlignment = _
xlCenterAcrossSelection

The problem is that it does not reset the range, it only takes the last
greatest width. For example Previously intMaxRow = 8 and I reset it to
intMaxRow = 4, it will still center it across the 8 rather than the 4.

Any thoughts




Sanj

Problem with xlCenterAcrossSelection
 
I used the following statement to reset the row alignment and then used the
HorizontalAlignment property and it works. Thank You for your help

.Range("2:2").HorizontalAlignment = xlLeft

Sanj

"Tom Ogilvy" wrote:

Before changing intMaxRow, try resetting the old range's HorizontalAlignment
to something else. Then try centering across.

--
Regards,
Tom Ogilvy

"Sanj" wrote in message
...
I am using the following piece of code to center a title across a changing
range, where intMaxRow (I know the wrong row, column reference) is the

last
column.

.Range("A2").Resize(1, intMaxRow).HorizontalAlignment = _
xlCenterAcrossSelection

The problem is that it does not reset the range, it only takes the last
greatest width. For example Previously intMaxRow = 8 and I reset it to
intMaxRow = 4, it will still center it across the 8 rather than the 4.

Any thoughts






All times are GMT +1. The time now is 05:04 AM.

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