Solved

VBA Excel 2010 - Selecting columns

Posted on 2011-09-16
7
327 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
[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
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

759 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