Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

hiding multiple columns

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Hiding Multiple Columns

Hiding Multiple Columns

ResolvedVersion 2010
Edited on Tue 9 Sep 2014, 14:31

Mark has attended:
Excel VBA Intro Intermediate course
Excel Advanced - For Power Users course
Excel PowerPivot course
Excel Dashboards for Business Intelligence course

Hiding Multiple Columns

I've used Macro recorder to hide alternate columns in a spreadsheet, when I've then assigned it to a button control and click the button it hides every column between the first and the last - Any help would be appreciated. I've used two different ways of recording it and neither work, the codes I've used are below;

1.
Range("K:K,M:M,O:O,Q:Q,S:S,U:U,W:W").Select Selection.EntireColumn.Hidden = True

2.
Columns("K:K").Select
Selection.EntireColumn.Hidden = True

Columns("M:M").Select
Selection.EntireColumn.Hidden = True

Columns("O:O").Select
Selection.EntireColumn.Hidden = True

Columns("Q:Q").Select
Selection.EntireColumn.Hidden = True

Columns("S:S").Select
Selection.EntireColumn.Hidden = True

Columns("U:U").Select
Selection.EntireColumn.Hidden = True

Columns("W:W").Select
Selection.EntireColumn.Hidden = True


Thanks

RE: Hiding Multiple Columns

Hi Mark,

Thanks for your question. I recorded the same macro and mine works perfectly. My code looks similar to yours. My steps were as follows:

1. Turn on the macro recorder
2. While holding Ctrl, select the appropriate columns
3. Right-click on one of the column headers
4. Click Hide
5. Turn off the macro recorder

Then I unhid the columns and assigned a macro button.

My macro works every time when using the button.

Did you follow the same steps?

Give it another go in a new workbook. If it still doesn't work, please let us know.

Kind regards
Marius Barnard
Excel Trainer

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Move or Highlight Cells

Use any of your movement keys, cursor, Home, End, PgUp or PgDn to highlight cells rows or columns by holding down the Shift key as you move.

Use in combination with the Ctrl key for quicker movements.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.11 secs.