Solved

VBA Selecting/Highlighting Several Columns in Worksheet

Posted on 2016-09-09
3
32 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 50

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

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

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
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 use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

809 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