Solved

Excel - Increse columns in range by 5

Posted on 2016-11-21
6
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
Comment
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

by:
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

Open in new window

0
 
LVL 51

Expert Comment

by:Rgonzo1971
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

Open in new window

regards
0
 
LVL 33

Expert Comment

by:Rob Henson
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Closing Comment

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

Author Comment

by:chris pike
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

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.

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.

Join & Ask a Question