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