Solved

VBA Excel 2010 - Selecting columns

Posted on 2011-09-16
7
317 Views
Last Modified: 2012-05-12
Dear Experts,

Can you please have a short look on the attached code, in the first row I would like to select data range in column A and also in column E, after changing their colors.

In the current version it works but also changing color for B, C, D column data ranges.

Could you advise how to change it that only the A and E column data range should be changed?

thanks,
Range("A2:A" & LastRowWithValue & "", "E2:E" & LastRowWithValue & "").Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 14540253
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With

Open in new window

0
Comment
Question by:csehz
7 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 36548950
Try this:

With Range("A2:A" & LastRowWithValue)
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 14540253
    .TintAndShade = 0
    .PatternTintAndShade = 0
End With
With Range("E2:E" & LastRowWithValue)
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 14540253
    .TintAndShade = 0
    .PatternTintAndShade = 0
End With

Open in new window

0
 
LVL 1

Author Comment

by:csehz
ID: 36548979
Thanks basically I have this version through the macro recorder, just thought that maybe in one row can be done the selection.

Because anyway I have five such columns and looks the code quite long compare to the fact that it is just colouring

0
 
LVL 19

Accepted Solution

by:
regmigrant earned 500 total points
ID: 36549076
or this

I think you have overdone it with the quotes - try:-
Range("A2:A" & LastRowWithValue & ", E2:E" & LastRowWithValue & "").Select

0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 1

Author Closing Comment

by:csehz
ID: 36549102
Thanks that one I have searched
0
 
LVL 17

Expert Comment

by:andrewssd3
ID: 36549117
I think it will also work with subtle shift inyour commas and quotes to specify a non-contiguous range:

Range("A2:A" & LastRowWithValue & ",E2:E" & LastRowWithValue).Select

Open in new window

0
 
LVL 17

Expert Comment

by:andrewssd3
ID: 36549130
Sorry should have refreshed before posting
0
 
LVL 1

Author Comment

by:csehz
ID: 36549164
Never mind thanks that you dealt with the question,

thanks,
Zsolt
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

839 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