selective filtering so that select rows only if cell A or cell B contains a value

psychopedia

New Member
Joined
May 25, 2016
Messages
2
Hi:
I have a dataset that contains baseball record, I want to pick only one team to look at, so is there anyway I can apply filter on HomeTeam and VisitTeam so that if either HomeTeam or VisitTeam contains the team name, say PHI, the who row stays?

E.g: I have the data
HomeTeam VisitTeam
PHI CLE
ATL NYC
DET PHI

I want the first row and third row.

Thank you!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
try this:
Code:
Option Explicit


Sub foo()
    Dim lr As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row
    Dim i As Long


    For i = 2 To lr
        If Range("A" & i) = "PHI" Or Range("B" & i) = "PHI" Then
            Range("A" & i).EntireRow.Hidden = False
        Else: Range("A" & i).EntireRow.Hidden = True
        End If
    Next i
End Sub
 
Upvote 0
Alternatively, if you prefer a formula-only method, you can set up a Helper Column, say D:D, and a single cell that you'll use to specify the team of interest. Let's say that cell is C1, with the entry "PHI". Then the formula in D:D for all of the rows of interest could be something like
Code:
=IF( OR( A2 = $C$1, B2 = $C$1), 1, 0)
to list a column of 1's on rows that contain the team you want to examine. Then filter the sheet on that column, looking at all "1" values.
 
Upvote 0
try this:
Code:
Option Explicit


Sub foo()
    Dim lr As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row
    Dim i As Long


    For i = 2 To lr
        If Range("A" & i) = "PHI" Or Range("B" & i) = "PHI" Then
            Range("A" & i).EntireRow.Hidden = False
        Else: Range("A" & i).EntireRow.Hidden = True
        End If
    Next i
End Sub

Thank you! That works for me. Really appreciate it.
 
Upvote 0

Forum statistics

Threads
1,223,719
Messages
6,174,089
Members
452,542
Latest member
Bricklin

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