Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding columns

Status
Not open for further replies.

frosty7700

Programmer
Aug 10, 2001
95
US
Can someone tell me the best way to go about creating a macro to hide/show specific columns? The columns' data still needs to be used in formula calculations, but needs to be hidden for a simplified view. I've tried messing with the CustomView method but can't find much documentation on it.
 
Select your columns by click and drag in the column header area (where the letters are).
Right-click and select Hide.

To do it in VBA, record your key-strokes and see what results.
 
Here's a sample:

Hide a column by setting the width to 0
Code:
ActiveSheet.Columns("E").ColumnWidth = 0

Show a column - sets back xl's default width
Code:
ActiveSheet.Columns("E").ColumnWidth = 8.43


HTH

Cheers
Nikki
 
Personally, I would not use the columnwidth property for this purpose. It's easier to use
columns("E").hidden=true
that way, when you unhide, you automatically have the original width back.
Rob
[flowerface]
 
OK, I used the columns("x").hidden attribute, and it works pretty well. I had some issues with my macro when I tried selecting multiple columns at a time, where it would also hide columns tied to the columns I was hiding. But when I do it one-at-a-time, it works fine (though it's a bit slower...and it creates a sort of accordian effect).
 
Use
Code:
    Application.ScreenUpdating = False
before you begin hiding and
Code:
    Application.ScreenUpdating = True
when you finish.
 
Before you run the macro save your CurrentView
Views,CustomView,Add.. (with recorder on to get the VBA code)

Run your macro to hide columns

Save this as a second CustomView

Then you'll never need to run your macro again as you can quickly switch between views using CustomView.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top