Filtering Addresses for a Group of States

Written by Allen Wyatt (last updated April 19, 2025)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365


1

Richard has worksheet that consists of names and addresses. The addresses are broken into separate columns, such as Street, City, State, and ZIP Code. He is interested in filtering to display only those addresses in MN, OK, IA, and IL.

There are actually several different ways you can do the filtering. Before jumping into them, though, make sure that your data has a header row; I'll assume it is in row 1.

With that said, let's take a look at five or six different approaches you can take to get the addresses you want.

Using Filtering

To filter for the desired states, you can simply select a cell within your data and, on the Data tab of the ribbon, click the Filter tool. Excel automatically adds drop-down arrows next to the column headings in the first row.

Click the drop-down arrow next to the State column and, in the resulting drop-down palette, clear the check box next to Select All. This clears all the state check boxes. Then, go through the list and select the check boxes next to MN, OK, IA, and IL. When you click on OK, only addresses in those states are displayed.

Using Advanced Filtering

To utilize advanced filtering, you need to set up a criteria table. This can be done in some unused columns to the right of your data. (Just make sure you leave one or more blank columns between your data and the criteria table.) For instance, I could set up a criteria table starting in cell J1. (See Figure 1.)

Figure 1. A simple table for advanced filtering criteria.

Notice how simple the criteria table is—all you need to do is use a heading that is the same as column heading in your data table (in this case, "State") and then list under that each state you want—you don't even need to sort the states. Then you can follow these steps:

  1. Select one of the cells in your data. (Not in the criteria table.)
  2. Display the Data tab of the ribbon.
  3. Click the Advanced Filter tool (Excel 2007) or the Advanced tool (later versions of Excel) in the Sort & Filter group. Excel displays the Advanced Filter dialog box. (See Figure 2.)
  4. Figure 2. The Advanced Filter dialog box.

  5. Make sure the "Filter the List, In Place" radio button is selected. (It probably will be, by default.)
  6. The List Range should already be filled in, provided you did step 1.
  7. In the Criteria Range field, specify the cells where you created your criteria table. In this example I set it to J1:J5.
  8. Click on OK.

At this point, the data is filtered to display only rows having a state that matches one of the states in your criteria table.

Filtering in a Table

Another approach is to convert your data into a formal table in order to do the filtering. Just select a cell within the data and press Ctrl+T to display the Create Table dialog box. (See Figure 3.)

Figure 3. Creating a table.

The range of cells should automatically be added to the dialog box. Make sure the check box for "My Data Has Headers" is selected, then click on OK.

With the data in a formal table, a drop-down arrow appears next to the header row in each column. This should look familiar if you have read through this tip so far. All you need to do is to follow the same steps described earlier, under the "Using Filtering" heading. Click the drop-down arrow next to the State column, clear the check box next to Select All, then select the check boxes next to MN, OK, IA, and IL. When you click on OK, only addresses in those states are displayed.

Using a Formula

If you are using Excel 2021, Excel 2024, or Microsoft 365, you could use the FILTER function to extract the rows you want. Simply copy the column headers to a place to the right of your data; in this case, I'm going to assume that you are copying the headings from A1:F1 over to J1:O1. Then, in cell J2, place the following formula:

=FILTER(A:F,(E:E="MN")+(E:E="OK")+(E:E="IA")+(E:E="IL"))

The formula looks at the rows in columns A:F and, if column E contains one of the desired states, it returns the row.

If you want an even shorter formula and you are using Microsoft 365, then you can incorporate one of the latest regex-based functions. In that case, you would put the following formula into cell J2:

=FILTER(A:F,REGEXTEST(E:E,"^MN|OK|IA|IL$"))

The REGEXTEST function examines the values and column E (the states) and returns an array of rows that contain MN or OK or IA or IL. The vertical bar means "or," the caret means "starts with," and the dollar sign means "ends with." Thus, the function returns rows that contain only the desired two-character state names. In other words, if a state was listed as "Okla.", it wouldn't match the expression.

Using a Macro

If you wanted to use a macro to do the filtering, you could come up with one that examines the state column and if the state isn't one of the four you want, then row is hidden. Here's an example:

Sub Display_Addr()
    Dim r As Integer

    For r = 2 To Cells(Rows.Count, 5).End(xlUp).Row
        Select Case UCase(Cells(r, 5))
            Case "MN", "OK", "IA", "IL"
                Rows(r).EntireRow.Hidden = False
            Case Else
                Rows(r).EntireRow.Hidden = True
        End Select
    Next r
End Sub

The macro looks at column 5 (which is column E, in this example, the states column) and if it is one of the four desired states, then the row is displayed. Otherwise, the row is hidden. The macro runs very quickly, depending on the amount of data you have in the worksheet.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9951) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Embedding an Excel Worksheet

Word and Excel are both integral parts of Microsoft's Office suite of applications. As such, Word allows you to embed ...

Discover More

Adjusting Column Width Using Menus

If you want to resize the width of your table columns, you can do it using a mouse, but you can get more precise widths ...

Discover More

Specifying a Number of Matches

The wild card searching capabilities of Word are amazing. One thing you can do with wild cards is to specify not only a ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 365 applications with VBA programming. Written in clear terms and understandable language, the book includes systematic tutorials and contains both intermediate and advanced content for experienced VB developers. Designed to be comprehensive, the book addresses not just one Office application, but the entire Office suite. Check out Mastering VBA for Microsoft Office 365 today!

More ExcelTips (ribbon)

Showing Filter Criteria on a Printout

When you print out a filtered worksheet, you may want some sort of printed record as to what filtering was applied to the ...

Discover More

Filtering Based on Comparing Two Cells

Filtering can be very helpful in allowing you to see only those data records that meet certain criteria. In this tip you ...

Discover More

Copying the Results of Filtering

Filtering is a great asset when you need to get a handle on a subset of your data. Excel even makes it easy to copy the ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 7 - 3?

2025-04-20 11:41:56

J. Woolley

Step 5 of the Tip's 2nd method (Advanced Filtering) says, "The List Range should already be filled in, provided you did step 1." This applies only if you previously activated the Filter tool on the ribbon's Data tab as described in the Tip's 1st method (Filtering). Notice the Advanced Filter dialog allows you to put the result in a separate location (which must be on the same worksheet). This means the original data and its neighbors will not be disturbed by hidden rows (filter in-place).
The Tip's 4th method (Formula) also avoids hidden rows; you can even put the formula in a different worksheet or workbook. The Tip's formulas obviously assume the data is on the same worksheet in columns A:F with states in column E. These formulas will sort the filtered results by state (column 5):
    =SORT(FILTER(A:F, (E:E="MN")+(E:E="OK")+(E:E="IL")+(E:E="IA")), 5)
    =SORT(FILTER(A:F, REGEXTEST(E:E, "^MN|OK|IA|IL$")), 5)
Finally, here's an alternate version of the Tip's 5th method (Macro) which matches its 1st method (Filtering):

Sub Display_Addr2()
    'assume data in columns A:F with states in 5th column E
    Range("A:F").AutoFilter Field:=5, Operator:=xlFilterValues, _
        Criteria1:=Array("IA", "IL", "MN", "OK")
End Sub


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.