hiding multiple columns

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

Hiding Multiple Columns - B

resolvedResolved · Low Priority · Version 2010

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 - B

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

Read more: https://www.stl-training.co.uk/post-35325-hiding-multiple-columns.html #ixzz3CpMz6a7I

RE: Hiding Multiple Columns - B

Hello Mark,

I've recorded a macro identical to yours and mine seems to work fine. My code also looks similar. The steps I did were:

1. Start macro recorder
2. While holding Ctrl, select the relevant columns by clicking the column headers
3. Right-click on one of the column headers
4. Click Hide
5. Stop recording

I then drew a button and assigned the macro to it.

When I saved (as Macro enabled workbook), closed and reopened the workbook, the macro still worked right. It hid only the columns I selected.

Perhaps try it again following my steps? If you did similar steps before, there might be a different issue with your sheet.

Please do get back to us if you need further assistance.

Kind regards
Marius Barnard
Best STL

 

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:

Currency format

Ctrl+Shift+$ applies the Currency format, with two decimal places

View all Excel hints and tips


Server loaded in 0.07 secs.