Trying to hide 44 rows and 2 columns with a Macro.

jayd77

New Member
Joined
Mar 25, 2003
Messages
18
I am trying hide column A and B as well as even number rows 4-88. When I do this for some reason rows 10-30 get completely hidden in addition the other rows I am hiding. I have tried doing the macro over several times with no success. The odd numbered rows 11-29 are not listed in the macro VB code.

Columns("A:B").Select
Selection.EntireColumn.Hidden = True
Rows("4:4").Select
Range("C4").Activate
ActiveWindow.SmallScroll Down:=3
Range("4:4,6:6,8:8,10:10,12:12,14:14,16:16,18:18,20:20,22:22").Select
Range("C22").Activate
ActiveWindow.SmallScroll Down:=18
Range( _
"4:4,6:6,8:8,10:10,12:12,14:14,16:16,18:18,20:20,22:22,24:24,26:26,28:28,30:30,32:32,34:34,36:36,38:38,40:40" _
).Select
Range("C40").Activate
ActiveWindow.SmallScroll Down:=18
Range( _
"4:4,6:6,8:8,10:10,12:12,14:14,16:16,18:18,20:20,22:22,24:24,26:26,28:28,30:30,32:32,34:34,36:36,38:38,40:40,42:42,44:44,46:46,48:48,50:50,52:52,54:54,56:56,58:58" _
).Select
Range("C58").Activate
ActiveWindow.SmallScroll Down:=18
Union(Range( _
"68:68,70:70,72:72,74:74,76:76,4:4,6:6,8:8,10:10,12:12,14:14,16:16,18:18,20:20,22:22,24:24,26:26,28:28,30:30,32:32,34:34,36:36,38:38,40:40,42:42,44:44,46:46,48:48,50:50,52:52,54:54,56:56" _
), Range("58:58,60:60,62:62,64:64,66:66")).Select
Range("C76").Activate
ActiveWindow.SmallScroll Down:=12
Union(Range( _
"68:68,70:70,72:72,74:74,76:76,78:78,80:80,82:82,4:4,6:6,8:8,10:10,12:12,14:14,16:16,18:18,20:20,22:22,24:24,26:26,28:28,30:30,32:32,34:34,36:36,38:38,40:40,42:42,44:44,46:46,48:48,50:50" _
), Range("52:52,54:54,56:56,58:58,60:60,62:62,64:64,66:66")).Select
Range("C82").Activate
Selection.EntireRow.Hidden = True
Range("A1").Select
End Sub


I have tried modifying the code but get a syntax error. I don't know VB.
Any help would be appreciated.
Here is my modified code.



Columns("A:B").Select
Selection.EntireColumn.Hidden = True
Range( _
"4:4,6:6,8:8,10:10,12:12,14:14,16:16,18:18,20:20,22:22,24:24,26:26,28:28,30:30,32:32,34:34,36:36,38:38,40:40,42:42,44:44,46:46,48:48,50:50,52:52,54:54,56:56,58:58,60:60,62:62,64:64,66:66,68:68,70:70,72:72,74:74,76:76,78:78,80:80,82:82,84:84,86:86,88:88"_

).Select
Range("C88").Activate
Selection.EntireRow.Hidden = True
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi,
try the code
Code:
Sub hide()
Dim i As Integer
For i = 4 To 88 Step 2
    Range(i & ":" & i).EntireRow.Hidden = True
Next
End Sub
hope this helps
jindon
 
Upvote 0
Hey, do you have any idea why the macro wasn't working with the existing code created by recording a macro. Just curious!
 
Upvote 0
Hi,

I think, in your code, after the selection of multiple rows, you activated other cell.
So, selection is now a single cell and you are hiding that single row.
Have you checked it?

hope this helps

jindon
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,638
Latest member
Oluwabukunmi

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