Macro hiding the wrong columns!

SamAnnElizabeth

New Member
Joined
Mar 15, 2013
Messages
34
I'm trying to record a macro to return my sheet to the print display. I recorded it and then edited in visual basic. Here's the code:

Sub Hide()
'
' Hide Macro
'


'
Rows("1:60").Select
Selection.EntireRow.Hidden = False
Columns("A:AZ").Select
Selection.EntireColumn.Hidden = False
Rows("34:51").Select
Selection.EntireRow.Hidden = True
Rows("3:9").Select
Selection.EntireRow.Hidden = True
Columns("K:K").Select
Selection.EntireColumn.Hidden = True
Columns("P:P").Select
Selection.EntireColumn.Hidden = True
Columns("AG:AX").Select
Selection.EntireColumn.Hidden = True
Range("A1").Select
End Sub


When I run it, it hides columns G:Q and Z:AX. The rows are right. I have no merged cells in the range. Does anyone have any ideas what I could do differently? Thanks!
 
When attaching code to a button, it's best to explicitly reference sheet names, instead of depending on what the active sheet is.

Try

Rich (BB code):
Sub Hide()
'Adjust sheet name here
With Sheets("Sheet1")
    .AutoFilterMode = False
    .Rows("1:60").EntireRow.Hidden = False
    .Columns("A:AZ").EntireColumn.Hidden = False
    .Rows("34:51").EntireRow.Hidden = True
    .Rows("3:9").EntireRow.Hidden = True
    .Columns("K:K").EntireColumn.Hidden = True
    .Columns("P:P").EntireColumn.Hidden = True
    .Columns("AG:AX").EntireColumn.Hidden = True
End With
End Sub
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I tried deleting the button and even inserted the following line at the beginning: Sheets("All Programs").Select

The error I get is "ShowAllData Method of Worksheet class failed"
 
Upvote 0
I'm pretty sure it's perfect now. I'm using this:

Sub Hide()
'
' Hide Macro


With Sheets("All Programs")
AutoFilterMode = False
ActiveSheet.ShowAllData
Rows("1:60").Hidden = False
Columns("A:AZ").Hidden = False
Rows("34:51").Hidden = True
Rows("3:9").Hidden = True
Columns("K:K").Hidden = True
Columns("P:P").Hidden = True
Columns("Z:AA").Hidden = True
Columns("AG:AX").Hidden = True
Range("A1").Select
End With
End Sub


Thank you SOOO much!
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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