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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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,214,641
Messages
6,120,692
Members
448,979
Latest member
DET4492

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