Solved

# Excel - Increse columns in range by 5

Posted on 2016-11-21
54 Views
Last Modified: 2016-11-21
Hi Experts,
I need VBA to increase all COLUMNS in a selected range by  +3

Range("A:A,B:B,C:C,D:D,E:E,F:F,G:G,H:H,O:O,R:R,U:U").Select

I tried taking the sub for increasing rows, which works, and changed it to columns, but it does not work. It increases ALL columns in the sheet  not the desired columns.

Here is what I tried...................
Sub TEST()
' test

Dim column As Range
For Each column In Range("A:A,B:B,C:C,D:D,E:E,F:F,G:G,H:H,O:O,R:R,U:U").Columns
Columns.ColumnWidth = column.ColumnWidth + 5
Next column
End Sub

Thanks so much
Chris
0
Question by:chris pike
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions
• 3
• 2
6 Comments

LVL 33

Accepted Solution

Rob Henson earned 500 total points
ID: 41896193
Try this:

``````Sub Increase_Column_Width()

For C1 = 1 To 6
CW = Cells(1, C1).ColumnWidth
Cells(1, C1).ColumnWidth = CW + 5
Next C1

For C2 = 15 To 21 Step 3
CW = Cells(1, C2).ColumnWidth
Cells(1, C2).ColumnWidth = CW + 5
Next C2

End Sub
``````
0

LVL 51

Expert Comment

ID: 41896213
Hi,

pls try
``````Sub TEST()

Dim col As Range
For Each col In Range("A:A,B:B,C:C,D:D,E:E,F:F,G:G,H:H,O:O,R:R,U:U").Columns
col.ColumnWidth = col.ColumnWidth + 5
Next col
End Sub
``````
regards
0

LVL 33

Expert Comment

ID: 41896229
@Rgonzo - is the error in Chris's script because column is already a defined word so can't be used as a variable?

If not maybe the error is in the line:

Columns.ColumnWidth = column.ColumnWidth + 5

should be:

column.ColumnWidth = column.ColumnWidth + 5

note removal of "s" from column in first part.
0

Author Closing Comment

ID: 41896262
Thanks,
That was an easy one.
0

Author Comment

ID: 41896268
Rgonzo1971
Sorry I didn't even see your comment when I awarded Rob
I didn't refresh screen , so I didn't see any additional comments.

But thanks for helping.
0

Author Comment

ID: 41896269
I do have a related question to this question.
Posting now
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
###### Suggested Courses
Course of the Month1 day, 17 hours left to enroll

#### 710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.