Solved

How to trim many cells at once?

Posted on 2008-01-31
Medium Priority
1,626 Views
I have 60,000 cells storing zip codes. Most are 5 digit. But a few hundred are 9 digit and this is interferring with my ability to do a multi-value filter accurately.

How do I tell excel to trim the 9-digit zips to 5 digits?
0
Question by:polaatx
• 5
• 4
• 2
• +2

LVL 10

Expert Comment

ID: 20792624
You filed your excel 2003 request under the zone  Computer Hard Drives
0

Author Comment

ID: 20792666
Is there a way to move it to correct category or shall I post a new question?
0

LVL 10

Expert Comment

ID: 20792694
I'd just go on and post a new one.
Submitt a reuqest for this question to be removed.
0

Author Comment

ID: 20792748
How do I submit a request  to be removed?
0

LVL 8

Expert Comment

ID: 20793291
The formula you need is =LEFT(A1,5) (with the zipcode in cell A1).
0

Author Comment

ID: 20794126
Hello,

I'm sorry but it's been years since I worked with excel formulas. How do I apply the formula you provided? I mean the cell already has data in it.

Do I need to apply the formual to an empty cell to create new trimmed values and then paste them back over the old untrimmed values? or is there a way to in one step trim all the values?
0

LVL 8

Assisted Solution

csoussan earned 1200 total points
ID: 20794244
Lets say the zipcode list starts in cell A1 and goes down to cell A60000.  I would:

1) create the formula   =left(A1,5)   in column B1 (insert a blank column if necessary next to the column with the zipcodes)
2) click on cell B1 to make sure the cell pointer is on B1
3) double-click the small black square on the bottom right-hand corner of the cell.  This will copy the formula from cell B1 through B60000 (assuming the zipcodes in column A are in every cell through to cell A60000).
4) Cells B1:B60000 should be highlighted.  At this point, assuming you want the trimmed values you've just created to replace the values in Column A, click on copy and then place the cell pointer on cell A1 and select Edit --> Paste Special, select Values and click OK.  This will replace the cell contents with the new trimmed values.

I hope this helps.
0

Author Comment

ID: 20794320
Okay I will try this tommorrow when I come back to work. Thanks a bunch for the quick replies.
0

LVL 85

Assisted Solution

Rory Archibald earned 400 total points
ID: 20795929
If your zips are entered as nnnnn-nnnn, you could select your data and press Ctrl+H to bring up the replace dialog, then enter -* in the Find box and leave the replace box blank, then hit Replace All. If they are just entered as 9 digits then you will need the formula approach.
Regards,
Rory
0

LVL 17

Assisted Solution

Shanmuga Sundaram earned 400 total points
ID: 20796235
Though you have not mentioned to trim either the first five digits or the last five digits please use as you need. lets assume that your zip code is in column A then to get the first 5 digits as zip code then you should type in B1 cell as =Left(A1,5). Copy this and paste to all the other cells in B column. if you want to get the last 5 digits as zip code then you should type in B1 cell as =Right(A1,5). Copy this and paste to all the other cells in B column.
0

LVL 8

Expert Comment

ID: 20800213
Also, if you have any spaces preceding your zip code, you would need to first eliminate the spaces beofre you use the =Left(A1,5) formula as the space would could towards the 5 characters that are referenced in the =Left(A1,5) formula.  The easiest way to make sure leadin spaces do not trip you up is to make the formula =Left(Trim(A1),5).  I've attached a spreadsheet giving you an example of how this would work with zip codes that have spaces, don't have spaces, have dashes, have only five digits, etc.  Let me know if you have any questions.
Zips.xls
0

LVL 8

Accepted Solution

csoussan earned 1200 total points
ID: 20800450
I noticed a couple of typos so I'm reposting with the typo corrected for ease in readability.
------------------------------
If you have any spaces preceding your zip code, you would need to first eliminate the spaces before you use the =Left(A1,5) formula as the space would count towards the 5 characters that are referenced in the =Left(A1,5) formula.  The easiest way to make sure leading spaces do not trip you up is to make the formula =Left(Trim(A1),5).  I've attached a spreadsheet giving you an example of how this would work with zip codes that have spaces, don't have spaces, have dashes, have only five digits, etc.  Let me know if you have any questions.
Zips.xls
0

Author Closing Comment

ID: 31426972
Again, very grateful.
0

Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.