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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

iggydarsa

Well-known Member
Joined
Jun 28, 2005
Messages
1,647
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
 

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,484
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
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
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 !
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,625
Messages
5,832,748
Members
430,163
Latest member
YesImAk

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
Top