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,081,904
Messages
5,361,996
Members
400,667
Latest member
cryptomike

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top