VBA to Hide Rows for certain criteria

JayhawkRacer

New Member
Joined
Feb 24, 2014
Messages
4
New member here!

I've had good luck with some code written to hide rows when the cell in column "A" is blank(for a certain range of rows), but I tried to modify it to hide rows that have "Complete" in column "D" and it works, but only after freezing excel for a time.

Here's my original code for hiding rows with blank cells in column "A": (This works great)

Code:
Sub HideBlankPoundProtoRows()
    ActiveSheet.Unprotect Password:="garmin"
    Application.ScreenUpdating = False
    Range("A103").Select
    Do Until ActiveCell.Address(False, False) = "A258"
    If IsEmpty(ActiveCell) Then
        Selection.EntireRow.Hidden = True
        ActiveCell.Offset(1, 0).Select
    Else
        ActiveCell.Offset(1, 0).Select
    End If
    Loop
    Application.ScreenUpdating = True
    Range("G101").Select
    ActiveSheet.Protect Password:="garmin"
End Sub

And here's my modified code, as I said, it works, but only after freezing my application for several minutes and then I have to hit "end" or "debug" and excel responds and shows exactly what I wanted. Can anyone spot what might cause the hangup?

Code:
Sub HideCompletePoundProtoRows()
    ActiveSheet.Unprotect Password:="garmin"
    Application.ScreenUpdating = False
    Range("D103").Select
    Do Until ActiveCell.Address(False, False) = "D258"
    If ActiveCell.Value = "Complete" Then
        Selection.EntireRow.Hidden = True
        ActiveCell.Offset(1, 0).Select
    Else
        ActiveCell.Offset(1, 0).Select
    End If
    Loop
    Application.ScreenUpdating = True
    Range("G101").Select
    ActiveSheet.Protect Password:="garmin"
End Sub

One caveat is that the cells in column "D" only look like they are saying "complete", when it's really a long formula that returns "complete" based on other criteria.

Thanks in advance for help!
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try:
Code:
Sub HideCompletePoundProtoRows()
    ActiveSheet.Unprotect Password:="garmin"
    Application.ScreenUpdating = False
    Dim rng As Range
    For Each rng In Range("D103:D258")
        If rng = "Complete" Then
            Rows(rng.Row).EntireRow.Hidden = True
        End If
    Next rng
    Application.ScreenUpdating = True
    Range("G101").Select
    ActiveSheet.Protect Password:="garmin"
End Sub
 
Upvote 0
Could've also used autofilter
Code:
Sub HideCompletePoundProtoRows()
ActiveSheet.Unprotect Password:="garmin"
    With ActiveSheet.Range("D3:D258")
        .AutoFilter
        .AutoFilter Field:=1, Criteria1:="<>*Complete*"
    End With
ActiveSheet.Protect Password:="garmin"
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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