Macro to Hide Columns

bfeller

New Member
Joined
Oct 9, 2004
Messages
15
I have a spreadsheet containing numerous worksheets. Within three of these worksheets, I would like to create a macro to hide 2 columns (all the same columns, F & H). The macro I've created so far is deleting way too many columns and so I'm obviously doing something wrong. Anyone have a suggestion for a macro to make this work?

Eventually I would like to also add a "print" function to the macro, but want to get the hide columns thing to work first. Essentially, this is a spreadsheet that goes out to our whole team an everyone prints different stuff and the spreadsheet itself is formatted more for input than output. Therefore, I'm working on inserting a "button" for everyone to push that will clean up the spreadsheet and print the same worksheets.Thanks!

Brian
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
You didn't give any information about what worksheets you wanted to do this with, but in general how about:

Code:
Sub test()
Columns(6).Hidden = True
Columns(8).Hidden = True
End Sub
 
Upvote 0
This is the code I ended up with after attempting to record the macro to use:

Sub Hide_Columns()
Sheets("Loans in Closing").Select
Range("F:F,H:H").Select
Selection.EntireColumn.Hidden = True
Sheets("Pipeline").Select
Range("F:F,H:H").Select
Selection.EntireColumn.Hidden = True
Sheets("Closed Loans - NEW").Select
Range("F:F,H:H").Select
Selection.EntireColumn.Hidden = True
End Sub

This is the one that hides too many rows.
 
Upvote 0
Okay, since we have worksheet names now, try:

Code:
Dim ws As Worksheet

    For Each ws In Worksheets(Array("Loans in Closing", "Pipeline", "Closed Loans - NEW"))
        ws.Range("E:E,H:H").EntireColumn.Hidden = True
    Next ws

Hope that helps!
 
Upvote 0

Forum statistics

Threads
1,207,438
Messages
6,078,561
Members
446,349
Latest member
Malroos7912

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top