display columns

M

mwam423

greetings, i have macro which runs query on database with over 100 columns.
when macro is finished i want to display only those columns i've run the
query on, anywhere from two to twenty columns.

therefore i hide all the columns of database and have a range which lists
each column to display by number (col A =1, col B = 2, etc.) what type of
code would i use to display the columns.

have used "EntireColumn.Hidden = false" but only seems to work for single
column at a time, which would work with a loop. but i'm hoping there's some
code that would unhide all the columns at once, any help greatly appreicated.
 
W

Wigi

Hi

For instance: Range("A1,C1,F1").EntireColumn.Hidden = True

But a small loop is not so inefficient in this case.
 
C

Chip Pearson

There are many ways to address ranges, but the following code may give you a
start.


Dim R As Range
With Worksheets("Sheet1")
Set R = .Range("A1, C1, E1")
R.EntireColumn.Hidden = True
' OR
Set R = Application.Union( _
.Cells(1, 1), .Cells(1, 3), .Cells(1, 5))
R.EntireColumn.Hidden = True
End With



--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
M

mwam423

hi wigi and chip, i was hoping there was a way i could use the column numbers
en masse. yes, am using a loop and that works fine as the query rarely needs
to display more than twenty columns. appreciate the responses!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top