HELP! - Hiding colums Macro

mobilesuit818

New Member
Joined
Sep 13, 2006
Messages
48
Hello,
I need to hide several columns (those columns are F, Q, R S, T, U, W, X, and Y) when im finished working a worksheet. There are several worksheets in my workbook.

Can someone help with a macro for this, please?
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
How's this:

<font face=Tahoma><SPAN style="color:#00007F">Sub</SPAN> HideColumns()
    <SPAN style="color:#00007F">Dim</SPAN> ws <SPAN style="color:#00007F">As</SPAN> Worksheet
        <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> ws <SPAN style="color:#00007F">In</SPAN> ActiveWorkbook.Worksheets
            ws.Range("F:F, Q:Y").EntireColumn.Hidden = <SPAN style="color:#00007F">True</SPAN>
        <SPAN style="color:#00007F">Next</SPAN> ws
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Just set to False to unhide.

HTH,

Smitty
 

mobilesuit818

New Member
Joined
Sep 13, 2006
Messages
48
Thank you
Where do you input this. In what Module?
Also, once I copy and paste, do I need to save?
So what would initiate the Macro or how do I get the macro to work.?
 

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
In the VBE just got Insert-->Module and paste the code there.

Yes, you'll need to save the workbook in order to save the code.

As for getting it to work, you can call the macro from the Macro menu, assign it to a keyboard shortcut, draw a Forms button and assign it to that, or tie it to an event.

Smitty
 

mobilesuit818

New Member
Joined
Sep 13, 2006
Messages
48
Actually, what would the formula be if I just wanted to use this only on single worksheet in a workbook, instead of the entire workbook?

Is there a macro that I can run to undo it?


Can anyone help me with these?
 

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
Code:
Sub foo()
  ActiveSheet.Range("F:F, Q:Y").EntireColumn.Hidden = True
End Sub

But you've got your terminology a bit mixed up. The above code will only act on the Active Worksheet, whereas the other will work on every Worksheet in the entire Workbook.

Smitty
 

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
No problem.

Is there a macro that I can run to undo it?

Just copy the macro and rename it, then change "= True" to "= False".

Smitty
 

Forum statistics

Threads
1,171,060
Messages
5,873,535
Members
432,982
Latest member
meepio

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
Top