Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Formatting different zip code types within a column

In Excel, with the .csv file extension, we have a column of zip codes that
are set up differently for each record. For an example, we will have 6037,
60371022 and 25463. If we highlight the whole column and select "zipcode",
the 6037 becomes 06037 (like it should), the 25463 stays the same, but the
60371022 doesn't get the leading zero. If we use the zip plus 4, then the
6037 becomes 06037-0000 which is also incorrect. Is there a way to format
all three types at the same time without doing too much manual manipulation?
Please advise. Thanks
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Formatting different zip code types within a column

The first step is to get the data in the column in pure text format. Re-name
a copy of the .csv file .txt.

This will evoke the Import Wizard. Tell the Wizard that the column is text.



The next step is to enter this macto in a standard module:

Sub going_postal()
Dim s As String
For Each r In Selection
s = r.Value
If Len(s) = 4 Then
s = "0" & s
End If
If Len(s) < 6 Then
r.Value = s
Else
If Len(s) = 8 Then
r.Value = "0" & Left(s, 4) & "-" & Right(s, 4)
Else
r.Value = Left(s, 5) & "-" & Right(s, 4)
End If
End If
Next
End Sub

The third step is to select the cells you want to convert and run the macro.
If you start with:
08549
8549
85491234
085491234

the macro will convert it into:
08549
08549
08549-1234
08549-1234


If you need any help installing and running the macro, just update this post.
--
Gary''s Student - gsnu200724


"prizm" wrote:

In Excel, with the .csv file extension, we have a column of zip codes that
are set up differently for each record. For an example, we will have 6037,
60371022 and 25463. If we highlight the whole column and select "zipcode",
the 6037 becomes 06037 (like it should), the 25463 stays the same, but the
60371022 doesn't get the leading zero. If we use the zip plus 4, then the
6037 becomes 06037-0000 which is also incorrect. Is there a way to format
all three types at the same time without doing too much manual manipulation?
Please advise. Thanks

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Formatting different zip code types within a column

Try a custom format.

Format|Cells|Number tab|Custom category
[99999]00000-0000;00000

prizm wrote:

In Excel, with the .csv file extension, we have a column of zip codes that
are set up differently for each record. For an example, we will have 6037,
60371022 and 25463. If we highlight the whole column and select "zipcode",
the 6037 becomes 06037 (like it should), the 25463 stays the same, but the
60371022 doesn't get the leading zero. If we use the zip plus 4, then the
6037 becomes 06037-0000 which is also incorrect. Is there a way to format
all three types at the same time without doing too much manual manipulation?
Please advise. Thanks


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Formatting different zip code types within a column

That works perfectly except for the cells where the zip code is, for an
example, 27656 which is a valid zip code. It's changing it to 00002-7656.
How can I accommodate that? Thanks!

"Dave Peterson" wrote:

Try a custom format.

Format|Cells|Number tab|Custom category
[99999]00000-0000;00000

prizm wrote:

In Excel, with the .csv file extension, we have a column of zip codes that
are set up differently for each record. For an example, we will have 6037,
60371022 and 25463. If we highlight the whole column and select "zipcode",
the 6037 becomes 06037 (like it should), the 25463 stays the same, but the
60371022 doesn't get the leading zero. If we use the zip plus 4, then the
6037 becomes 06037-0000 which is also incorrect. Is there a way to format
all three types at the same time without doing too much manual manipulation?
Please advise. Thanks


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Formatting different zip code types within a column

Never mind! I wrote the formula wrong! Thanks! That was perfect and easy!

"Dave Peterson" wrote:

Try a custom format.

Format|Cells|Number tab|Custom category
[99999]00000-0000;00000

prizm wrote:

In Excel, with the .csv file extension, we have a column of zip codes that
are set up differently for each record. For an example, we will have 6037,
60371022 and 25463. If we highlight the whole column and select "zipcode",
the 6037 becomes 06037 (like it should), the 25463 stays the same, but the
60371022 doesn't get the leading zero. If we use the zip plus 4, then the
6037 becomes 06037-0000 which is also incorrect. Is there a way to format
all three types at the same time without doing too much manual manipulation?
Please advise. Thanks


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 error "some chart types cannot be combined with other chart types. Select a different chart types" roadsidetree Charts and Charting in Excel 15 June 2nd 09 10:53 AM
Mixed Column Types in One Chart LarryP Charts and Charting in Excel 1 March 1st 07 11:57 AM
Needed: Chart that combines clustered column and stacked column types Gerry Charts and Charting in Excel 3 February 14th 07 02:53 AM
Sun IF two data types are the same in a single column David_Williams_PG () Excel Discussion (Misc queries) 4 September 8th 06 06:24 PM
How do I mix column chart types? Ramesh Narasimhan Charts and Charting in Excel 1 July 20th 05 11:23 PM


All times are GMT +1. The time now is 11:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"