hiding multiple columns

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

Hiding Multiple Columns

resolvedResolved · Medium Priority · Version 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:

Wrapping Text in a Cell in an Excel 2010 Workbook

When you have a lot of text you want to put in a particular cell but you can't decrease the font size to fit because the text will then become ineligible, then manually wrap the text in a cell by simply pressing ALT+ENTER.

View all Excel hints and tips


Server loaded in 0.08 secs.