Written by Allen Wyatt (last updated October 6, 2018)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
Allan has a list of several hundred names and addresses. The street addresses range from Main Street, 123 Main Street, US RT 2, or 187 South Elm St. He would like to break out the street number from the addresses. So the address 123 Main Street would end up with "123" in one cell and "Main Street" in another. If there is no street number, then nothing ends up in the street number column. The Text to Columns tool will not work and he wonders how he can do this.
In a perfect world, Excel would allow you to easily split the numbers from the street names. Since this option doesn't exist, you have a couple of choices. The most time-consuming option involves adding an additional column and retyping the data. If, however, you would like to save some time, you can use a variety of formulas to accomplish the task.
Assuming the list of addresses is in column A (beginning in cell A1), you could use a formula similar to the following to pull out the numeric portion of the address:
=IF(ISERROR(VALUE(LEFT(A1,1))),"",LEFT(A1,FIND(" ",A1)-1))
Assuming you put the formula in cell B1, you could then use a different formula to derive the non-numeric portion of the address:
=TRIM(RIGHT(A1,LEN(A1)-LEN(B1)))
Note that this approach does have a limitation. Some addresses, especially in major metropolitan areas, use a format such as 152-33 Bell Blvd. The formulas above will work for these addresses, but if the alternative, 152 33 Bell Blvd., is used, the formula will parse incorrectly. Unless you want to buy a professionally developed address parsing program, the formulas above and a quick eyeball scan of the results should be adequate.
Another formula works in this case. Assuming your address is in cell A2, enter the following formula into cell B2:
=IF(ISNUMBER(VALUE(LEFT(A2,1))),VALUE(LEFT(A2,FIND(" ",A2)-1)),"")
This formula is saying, "If the first character is not a number, leave the cell blank. Otherwise, give me all of the characters on the left out to, but not including, the first space." You can then use the result of this formula to pull out the non-numeric portion of the address:
=IF(B2="",A2,MID(A2,FIND(" ",A2)+1,99))
Another approach is to use an array formula. Here again, assuming your address is in cell A2, you can use the following:
=IF(ISNUMBER(1*MID(A2,ROW($1:$1),1)) = TRUE,LEFT(A2,FIND(" ",A2,1)),"")
Since this is an array formula you need to enter it by using Ctrl+Shift+Enter. The result is that the formula returns the leading numeric portion of the address. You can then determine the non-numeric portion by using the following array formula:
=IF(ISNUMBER(1*MID(A2,ROW($1:$1),1))=TRUE,RIGHT(A2,LEN(A2)-FIND(" ",A2,1)),A2)
Finally, the following macro can be used to break-out the street address from the street name.
Sub GetStreetNum() Dim sStreet As String Dim J As Integer Dim iNum As Integer For Each cell In Selection sStreet = cell.Value J = InStr(sStreet, " ") If J > 0 Then iNum = Val(Left(sStreet, J)) If iNum > 0 Then cell.Offset(0, 1).Value = iNum sStreet = Trim(Mid(sStreet, J, Len(sStreet))) End If End If cell.Offset(0, 2).Value = sStreet Next End Sub
To use this macro, simply select the range of cells that contain your addresses and then run it. The leading numeric portion of the address will appear in the cell to the right of each address and the balance of the address will be placed in the cell to the right of that. (So you should make sure that there are two blank columns to the right of the addresses you select.)
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (8031) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Extracting Street Numbers from an Address.
Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!
If you want to add a dynamic statement to a worksheet that indicates how many rows are in a data table, you might be at a ...
Discover MoreIf you have a series of consecutive numbers in a column, you may want to know if it really is consecutive. (In other ...
Discover MoreIf you've got a list of names in a column, you may want to change the order of each name. For instance, the name have the ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2023 Sharon Parq Associates, Inc.
Comments