Macro to hide all rows that ...

thankyou

Board Regular
Joined
Aug 13, 2008
Messages
189
Looking for a VBA module that will hide all rows except adjacent rows that have "9" as their value in one cell of column B, and "5" in the cell below it, like this:

Column B

1
9
5

18
23
3
11
5
9
4
9
5

22

So, in the above example, you'd hide all rows except the ones I've bolded for you here, namely rows 2,3,11 & 12, leaving:

Column B

9
5
9
5
etc


That will allow me to do analytics on adjacent rows that have "9" in column B and "5" in the cell below it.

Thanks a lot!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try:
Code:
Sub HideRows()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim rng As Range
    For Each rng In Range("B2:B" & LastRow)
        If (rng = 9 And rng.Offset(1, 0) = 5) Or (rng = 5 And rng.Offset(-1, 0) = 9) Then
            Rows(rng.Row & ":" & rng.Row + 1).Hidden = False
        Else
            Rows(rng.Row).Hidden = True
        End If
    Next rng
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
beautiful. let me give that a shot. Looks like that took a lot of focus. Will follow up shortly. thanks so much
 
Upvote 0
yeah mumps, that was perfect. I like the way you think!
huge thanks.
PS sorry it took me about 30mins longer than I was thinking I might be, fumbling my way around, but I think that's the only way to learn this stuff and I was able to make my way through it. great job. appreciate you and hope you're finding the answers you're looking for here because I'll bet you're learning a lot every day too.
thanks again.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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