Solved

VBA Selecting/Highlighting Several Columns in Worksheet

Posted on 2016-09-09
3
28 Views
Last Modified: 2016-10-20
I have a worksheet with a table, with columns 1 and 12. I would like to highlight columns 1 and 10.

This code doesn't work because only one column can be selected. Is there a way/trick that I can make this work?

Sub SelectColumns()

Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Orders")

ws.Select
ActiveWindow.zoom = 80

Dim lo As ListObject
Set lo = ws.ListObjects("Orders")

lo.DataBodyRange.Columns(1).Resize(, 1).Select
lo.DataBodyRange.Columns(10).Resize(, 1).Select

Set ws = Nothing
Set lo = Nothing

End Sub

Open in new window

0
Comment
Question by:Massimo Scola
3 Comments
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41791070
Hi,

pls try

Union(lo.DataBodyRange.Columns(1).Resize(, 1), _
lo.DataBodyRange.Columns(10).Resize(, 1)).Select

Open in new window

shorter

Union(lo.DataBodyRange.Columns(1), _
lo.DataBodyRange.Columns(10)).Select

Open in new window

Regards
1
 

Author Comment

by:Massimo Scola
ID: 41846519
That's great.
It works properly.

Thanks
0
 
LVL 14

Expert Comment

by:frankhelk
ID: 41851689
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: Rgonzo1971 (https:#a41791070)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

frankhelk
Experts-Exchange Cleanup Volunteer
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

813 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now