Solved

VBA Selecting/Highlighting Several Columns in Worksheet

Posted on 2016-09-09
3
38 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
[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 Comments
 
LVL 51

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

Independent Software Vendors: 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!

Question has a verified solution.

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

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!
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

739 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