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!
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
What is it that is wrong?

You say the wrong columns are hidden, which columns are you expecting to be hidden?


You can write the code without selecting anything
Code:
Sub Hide()
'
' Hide Macro
'

'
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
Range("A1").Select
End Sub
 
Last edited:
Upvote 0
By Clear Filtering, do you mean turn OFF any filters (dropdowns no longer visible)?
Oor just clear any criteria that had been selected by the filters?
 
Upvote 0
This line will clear any criteria that has been set by autofilters

ActiveSheet.ShowAllData
 
Upvote 0
Ugh, I'm having another problem now.

I tried to insert a button for the Macro and it's now telling me that there is an error with the ActiveSheet.ShowAllData command when there wasn't before I tried to add the button.

Any advice?
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,454
Members
448,898
Latest member
drewmorgan128

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