Change column width

Hatye

Board Regular
Joined
Jan 11, 2010
Messages
143
Hi,
I want to change column width on the following columns in my worksheet: O, S, W, AA, AE, AI from 2 to 1.
What I have is this:

Code:
    Range("O:O,S:S,W:W,AA:AA,AE:AE,AI:AI").Select
    Selection.ColumnWidth = 1
The problem is that it is selecting all columns from B to AI. I have some merged cells whitin the range, so I guess that that has something to do about it, but I can't figure out what to do. Can anyone help me with this? :)
However, it does work when I do it manually (when recording the macro).
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Do you have a row that doesn't have any merged cells? Maybe you should be using the horizontal alignment 'Center across selection' instead of merged cells.
 

Hatye

Board Regular
Joined
Jan 11, 2010
Messages
143
Hi Andrew Poulsom and than you for the reply,

No, I don't have any whole columns that don't contain merged cells. It is unfortunately a lot of work to not use merged cells. This is a report template, which is specially adapted to different purposes. All columns width are 2, and it uses merged cells actively to get the correct layout for the report.
Now there is a report which needs to be adjusted, so that the columns mentioned in the first post must have the width 1.

Since it works when I do it manually, shouldn't it work with when I run it as a macro?
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
I asked about rows not columns. Surely you haven't merged the cells in every row of the columns whose width you want to change?
 

Hatye

Board Regular
Joined
Jan 11, 2010
Messages
143
Oh, I'm sorry, I misread; my fault!

Yes, I have several rows that doesn't conatain any merged cells. E.g. row 1, 6, 9, 40.
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
This worked for me:

Code:
Range("O1:O1,S1:S1,W1:W1,AA1:AA1,AE1:AE1,AI1:AI1").ColumnWidth = 1
 

Forum statistics

Threads
1,085,693
Messages
5,385,224
Members
401,936
Latest member
stephenpoff

Some videos you may like

This Week's Hot Topics

Top