Hiding multiple rows

Mike1

New Member
Joined
Jun 7, 2011
Messages
23
I need help hiding rows using a macro. I have no prolem hiding an individual row based on a value, but I want to go one step further and given a value in one row, I want to hide that row and the next two rows. Below is what I have to hide an individual row:

Sub wind()
For a = 221 To 221
If Cells(a, 1) = 0 Then
Cells(a, 1).Select
Selection.EntireRow.Hidden = True
End If
Next a
End Sub

What I want to do is if A221=0, I want to hide not just row 221, but I want to hide rows 221-223. Can you help?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Welcome to the board..

Try

Rich (BB code):
For a = 2 To 221 Step 3
    Cells(a, 1).Resize(3, 1).EntireRow.Hidden = Cells(a, 1).Value = 0
Next a
End Sub

Hope that helps.
 
Upvote 0
Maybe like this

Code:
Sub wind()
For a = 2 To 221
    If Cells(a, 1).Value = 0 Then Cells(a, 1).EntireRow.Resize(3).Hidden = True
Next a
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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