# How to trim many cells at once?

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?
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Software Engineer -- ConsultantCommented:
You filed your excel 2003 request under the zone  Computer Hard Drives
0
Author Commented:
Is there a way to move it to correct category or shall I post a new question?
0
Software Engineer -- ConsultantCommented:
I'd just go on and post a new one.
Submitt a reuqest for this question to be removed.
0
Author Commented:
How do I submit a request  to be removed?
0
Commented:
The formula you need is =LEFT(A1,5) (with the zipcode in cell A1).
0
Author Commented:
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
Commented:
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 Commented:
Okay I will try this tommorrow when I come back to work. Thanks a bunch for the quick replies.
0
Commented:
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
Director of Software EngineeringCommented:
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
Commented:
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
Commented:
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

Experts Exchange Solution brought to you by