Sei sulla pagina 1di 5

What is an Excel Substring?

Some programming languages have a substring function, but not Excel. However,
there are several text formulas that can achieve the desired result.

When we speak of a substring, we just mean a portion or subset of a cell’s


contents. For example, if the cell contained 1001 Drake Ave., any of these items
could be a substring:

 1001
 Drake Ave.
 100
 rake

The Problem
Many membership databases or mailing lists are set up with defined fields for First
Name, Last Name, Street, City, State, and Zip. This format works fine if you’re
creating a mailing label as the post office relies on zip code sorting.

But what if you need to do door-to-door canvassing to check on neighbors or to


inform people about an upcoming ballot measure?

If you pull this type of list into Excel and sort on Street, you get a list that is
numerically sorted. As you can see in the example below, the Drake Ave records are
not together.
Excel with single Street field

Ideally, you would like to sort the list so all the Drake Ave entries are together. There
are several ways to do this in Excel, but one way is to create two columns from the
Street field.

The first column reflects the street number substring and the second the street name
substring. You can then resort the list based on the street name and street number.

If the addresses are simple, you could probably use the Text to Columns wizard.

How to Extract Street Numbers using LEFT


1. Import your data into Microsoft Excel or use the sample spreadsheet in the Resources
section.
2. In cell D1, type Nbr.
3. In cell E1, type Street Name
4. In cell D2, type the following Excel formula =LEFT(C2,(FIND(" ",C2,1)-1))
5. Press Enter. The value 1001 should show in D2

In Step 4, our Excel formula will look at the original street value in cell C2
(1001 Drake Ave.) and extract the contents up to, but not including the first
space. The FIND function is used to find the blank.

The next part involves copying this formula to the rest of the entries. However,
we need to reference the correct street cell and not use C2 for the remaining
rows.

6. Click cell D2 to select the beginning of our range.


7. Move your mouse to the lower right corner.

Copy the Excel formula down the column

8. Double-click the + cursor in lower right. This will copy your formula down the column.

In column D, you should see the extracted street numbers.

How to Extract Street Names using RIGHT,


We’ll now create a similar formula to capture the street address. This time, we will
grab the contents to the right of the first space from the Street column.
1. In cell E2, type the following formula =RIGHT(C2,LEN(C2)-FIND(" ",C2,1))
2. Press Enter. E2 should show as Alturas Dr.
3. Click cell E2 to select the beginning of our range.
4. Move your mouse to the lower right corner.
5. Double-click the + cursor in lower right. This will copy your formula down the column.

Columns D and E should contain the parsed contents from your original street
address.

Your spreadsheet should look similar to the one below.

Street Number and Names in new columns

Cleaning Up the Spreadsheet and Changing Cell


Format
The spreadsheet now has your split fields, but you should clean up the formulas. My
suggestion would be to convert the LEFT and RIGHT formulas to their respective
values. We did an earlier tutorial on copying and converting formulas to values.

After you convert the Nbr column, you probably want to change the format type to a
number.

1. Click column D.
2. Right-click and select Format cells...
3. On the Format Cells dialog, select Number.
4. Set Decimal places to 0.
5. Click OK.

Although our example is parsing one cell containing street information, you can use
the same steps to parse other types of entries. For example, Step 1 above is really
parsing everything but the first word because it is searching for a blank space. You
can alter the formula to find different values such as a comma.

Potrebbero piacerti anche