Hide Rows based on text in cell

VH5150

Board Regular
Joined
Mar 1, 2004
Messages
60
I have a worksheet that has the word "Yes" in intermittent cells throughout my worksheet in column L. I would like to write a macro that hides the entire row if the word "Yes" is present in column L. What is the code for this. My worksheet starts at row 22 and ends at row 210. Thanks!

This is round #2! Nobody responded initially.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try this:

Code:
Sub deleteRow()
    For i = 22 To 210
        If Range("L" & i) = "yes" Then
            Rows(i).Hidden = True
        End If
    Next i
End Sub
 
Upvote 0
Sample Code

Here some sample code: Adjust cells and ranges accordingly;


Sub Foo()
Dim Rng As Range
Dim Cell As Range
Set Rng = Range(Cells(3, "L"), Cells(20, "L"))
For Each Cell In Rng
If Cell.Value = "Yes" Then
Cell.EntireRow.Hidden = True
End If
Next
End Sub
 
Upvote 0
Hello, VH5150,
and hello, iggydarsa
(didn't we meet some hours ago ?)

take also a look at autofilter
custom "non equal to"

using code:
Range("L21:L210").AutoFilter Field:=1, Criteria1:="<>yes"
this would be faster then a loop when you have a lot of rows to check

kind regards,
Erik

EDIT: hello, jim may !
 
Upvote 0

Forum statistics

Threads
1,212,057
Messages
6,105,652
Members
447,974
Latest member
misspancake

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