Hiding/Unhiding multiple rows automatically based on cell condition

HansEmil

New Member
Joined
Nov 4, 2014
Messages
2
Hi,
I'm looking for a way to hide and unhide the rows based on the condition in D & E.
Lets say I want to list all documents that have TR00001 in D or E, I will type TR00001 into a cell(C3).
Doing this all other rows in the defined range shall be hidden.
If I type in TR00001 into cell C3, all documents with TR00002 in D or E should only be listed(it is ok to change active sheet to make it update).

[TABLE="width: 547"]
<tbody>[TR]
[TD="align: center"]C
[/TD]
[TD="align: left"]D
[/TD]
[TD="align: right"]E
[/TD]
[/TR]
[TR]
[TD]11. CS_0461-0003----[/TD]
[TD="align: left"]TR00001[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD]12. CS_0461-0003-E-CA-000-007[/TD]
[TD="align: left"]TR00001[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD]13. CS_0461-0003-Z-SA-100-013[/TD]
[TD="align: left"]TR00001[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD]14. CS_0461-0003-V-RA-100-006[/TD]
[TD="align: left"]TR00001[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD]15.CS_0461-0003-V-RA-100-007[/TD]
[TD="align: left"]TR00001[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD]16. CS_0461-0003-V-RA-100-009[/TD]
[TD="align: center"]0[/TD]
[TD="align: right"]TR00001[/TD]
[/TR]
[TR]
[TD]17. CS_0461-0003-V-XD-100-008[/TD]
[TD="align: center"]0[/TD]
[TD="align: right"]TR00002[/TD]
[/TR]
[TR]
[TD]18. CS_0461-0003-V-RA-100-015[/TD]
[TD="align: center"]0[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD]19. CS_0461-0003-Z-RA-000-008[/TD]
[TD="align: center"]0[/TD]
[TD="align: right"]0[/TD]
[/TR]
</tbody>[/TABLE]

I have been struggling for a while now with this issue as I'm very new to VBA coding.
I found a similar post here which I tried to edit to work for my application;
http://www.mrexcel.com/forum/excel-...-unhiding-multiple-rows-based-cell-value.html

I tried to modify the formula as follows, but it do not seem to work perfectly.
Code:
Private Sub Worksheet_activate()Dim Target As Range, x As Range
Set x = Range("C3")
Sheets("TR00001").Select
For i = 11 To 19
        Range("D" & i).Select
        If Range("D" & i).Value = x Then
            Rows(i & ":" & i).Select
            Selection.EntireRow.Hidden = False
            Range("D" & i).Select
    Else
            If Range("D" & i).Value <> x Then
            Rows(i & ":" & i).Select
            Selection.EntireRow.Hidden = True
            Range("D" & i).Select
    End If
    End If
        Range("E" & i).Select
        If Range("E" & i).Value = x Then
            Rows(i & ":" & i).Select
            Selection.EntireRow.Hidden = False
            Range("E" & i).Select
    Else
            
    End If
Next i
End Sub

Help and tips appreciated:)
Have a nice day.

Regards Hansi
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hiya
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim RwCnt As Integer

    If Not Target.Address = "$C$3" Then Exit Sub

    For RwCnt = 11 To 19
        If Range("D" & RwCnt) <> Target And Range("E" & RwCnt) <> Target Then
            Rows(RwCnt).Hidden = True
        Else
            Rows(RwCnt).Hidden = False
        End If
    Next RwCnt

End Sub
Edit
This needs to go in the sheet module
 
Upvote 0
That worked perfect! So easy when you know how it's done. I've been struggling for hours.
Thanks, Fluff!

Regards Hans E.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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