Solved

VBA Selecting/Highlighting Several Columns in Worksheet

Posted on 2016-09-09
3
17 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 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
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
Comment Utility
That's great.
It works properly.

Thanks
0
 
LVL 13

Expert Comment

by:frankhelk
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

771 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

12 Experts available now in Live!

Get 1:1 Help Now