excel SORTING HIDING WITH VBA

Youseepooo

New Member
Joined
Feb 5, 2019
Messages
37
hello

i have a code that works fine but id like to adjust it to add another criteria. I want to hide rows in Column "F5:F171" if they read "Inactive". It is currently hiding based on Yes/no in Column G just fine . I just want to hide based on 2 conditions.

Thanks

Code:
Sub sort_updated()

'removes No from Column G
Sheets("Log").Select
    Dim xRg As Range
    Application.ScreenUpdating = False
        For Each xRg In Range("g5:g420")
            If xRg.Value = "No" Then
                xRg.EntireRow.Hidden = True
            Else
                xRg.EntireRow.Hidden = False
            End If
        Next xRg
    Application.ScreenUpdating = True
    
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
What happens if G7=Yes 7 F7=Inactive, should that row be hidden?
Also what happens if the reverse is true?
 
Upvote 0
Try this

Code:
Sub sort_updated()


'removes No from Column G
    Sheets("Log").Select
    Dim xRg As Range
    Application.ScreenUpdating = False
    For Each xRg In Range("g5:g420")
[COLOR=#0000ff]        If xRg.Value = "No" And xRg.Offset(, -1) = "Inactive" Then[/COLOR]
            xRg.EntireRow.Hidden = True
        Else
            xRg.EntireRow.Hidden = False
        End If
    Next xRg
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
No if G reads "Yes" and F reads "Inactive" then it should be hidden. I want it to be governed by G. Good question man!
Thanks
 
Upvote 0
I tried restarting excel and my computer, its not running correctly. but it is running just not hiding rows with"Inactive" in f and No in G
 
Upvote 0
i actually think the process should be done as follows:
all values of "Yes" in Column G should appear filtered on the top and hide all rows with Inactive in Column F. SO instead of having to hide based on two criteria which seems to be more tricky, could you help me filter the yes to appear on top of the list while hiding all in active in column F.
 
Upvote 0
Still not sure entirely what your after, but how about
Code:
Sub sort_updated()

'removes No from Column G
Sheets("Log").Select
    Dim xRg As Range
    Application.ScreenUpdating = False
        For Each xRg In Range("g5:g420")
            If xRg.Value = "No" Or LCase(xRg.Offset(, -1)) = "inactive" Then
                xRg.EntireRow.Hidden = True
            Else
                xRg.EntireRow.Hidden = False
            End If
        Next xRg
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
lol how do u say u are not entirely sure what im after then your code runs perfect. haha
Thanks dude good work just what i wanted. :)
 
Upvote 0

Forum statistics

Threads
1,213,562
Messages
6,114,326
Members
448,564
Latest member
ED38

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