Filtering Cells in Microsoft Excel

horizontal rule

Contact   |   Help Topics   |   Excel 2000

Awhile back I was asked how to separate items in a cell such as names or addresses. My old solution was to save as text, then re-import into Excel, choosing the correct delimiter (e.g. a space or comma) to separate the items. Another option was to use the Text to Columns... option from the Data menu.

Now I've figured out a much more powerful and flexible way of doing it. Say you want to separate City, State and Zip. Here's the code; the explanation follows (NOTES: this tutorial assumes a basic knowledge of Microsoft Excel formulas. Also, the width of your window may wrap the formulas onto multiple lines, while they should actually be on only one line):

Example 1:

Try entering this into Excel now.
 ABCD
1 San Anselmo, CA 94960 =MID(A1,1,(FIND(",",A1)-1)) =MID(A1,(FIND(",",A1)+2),2) =MID(A1,(FIND(",",A1)+5),10)
Result:
1 San Anselmo, CA 94960 San Anselmo CA
94960

Brief Explanation:

The MID function returns a specific number of characters from a text string starting at the numeric position you specify, while the FIND function finds the numeric position of one text string within another. The FIND function is used to determine some of the arguments within the MID function.

Detailed Explanation:

Formula Syntax: MID(text,start_num,num_chars)

Formula Syntax: FIND(find_text,within_text,start_num)

Example 2:

first name last name
 ABC
1 Kevin Pedersen =MID(A1,1,(FIND(" ",A1)-1)) =MID(A1,(FIND(" ",A1)+1),30)
Result:
1 Kevin Pedersen Kevin Pedersen

Example 3:

last name, first name
 ABC
1 Parker-Jones, Mary Jane =MID(A1,(FIND(",",A1)+2),30) =MID(A1,1,(FIND(",",A1)-1))
Result:
1 Parker-Jones, Mary Jane Mary Jane Parker-Jones

Note that hyphens and spaces are ignored. The only thing needed in your data is a properly-spaced comma. The number 30 found in the formulas may be increased if your list of names conatins names that are longer than 30 characters (unlikely).
 
  Back to help topics



Last updated on the twenty-eighth of March, 2003.
Please use this contact form if you have any further questions.


made  
   with 
HTML