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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
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
 

jayd77

New Member
Joined
Mar 25, 2003
Messages
18
Thanks man! Your a genuis! It works perfectly. I really need to take a class on VB.
 

jayd77

New Member
Joined
Mar 25, 2003
Messages
18
Hey, do you have any idea why the macro wasn't working with the existing code created by recording a macro. Just curious!
 

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
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
 

Forum statistics

Threads
1,148,053
Messages
5,744,531
Members
423,881
Latest member
Nguyen Vu

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