Solved

VBA Selecting/Highlighting Several Columns in Worksheet

Posted on 2016-09-09
3
23 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:mscola
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:mscola
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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 will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

863 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

23 Experts available now in Live!

Get 1:1 Help Now