Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Mel07
 
Posts: n/a
Default Need to convert list of 5 digit zip codes to ranges where possible


I have been unable to figure this one out. I have over 2000 zip codes
in a single column (One 5 digit zip code per row) which are already
sorted in numeric order. I need to put these individucal zip codes
into ranges where possible when zip codes are sequential (i.e.
91714-91734). Is this possible outside of doing this manually because
it's killing me!!! Help.


--
Mel07
------------------------------------------------------------------------
Mel07's Profile: http://www.excelforum.com/member.php...o&userid=32458
View this thread: http://www.excelforum.com/showthread...hreadid=522385

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
bpeltzer
 
Posts: n/a
Default Need to convert list of 5 digit zip codes to ranges where possible

A couple questions. Are the zip codes numeric or text? And what do you want
if there's a loner?
If the codes are numeric, and loners can be shown as 'groups of one' (ex
22033-22033), then here's one approach. If the zip codes are in column A and
sorted in ascending order, beginning in row 2, use column B to designate what
group each zip belongs to. In B2 enter the number 1. In B3 enter the
formula =IF(A3=A2+1,B2,B2+1). Then in column C we'll create the ranges. In
C2 enter the formula =IF(B2=B3,"",INDEX(A:A,MATCH(B2,B:B,FALSE)) & " - " &
A2). Copy that down to C3. Then select B3:C3 and autofill down.
HTH. --Bruce

"Mel07" wrote:


I have been unable to figure this one out. I have over 2000 zip codes
in a single column (One 5 digit zip code per row) which are already
sorted in numeric order. I need to put these individucal zip codes
into ranges where possible when zip codes are sequential (i.e.
91714-91734). Is this possible outside of doing this manually because
it's killing me!!! Help.


--
Mel07
------------------------------------------------------------------------
Mel07's Profile: http://www.excelforum.com/member.php...o&userid=32458
View this thread: http://www.excelforum.com/showthread...hreadid=522385


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Duke Carey
 
Posts: n/a
Default Need to convert list of 5 digit zip codes to ranges where possible

As alternative to Bruce's suggestion, here's a macro that might do the trick

Sub zips()
Dim rng As Range
Dim strFirst As String
Dim intCurr As Long
Dim strlast As String
Dim rngTgt As Range
Dim x As Integer
Dim lTest As Long

Range("B1:B100").ClearContents

Set rngTgt = Range("B1")
strFirst = ""
strlast = ""
intCurr = 0
For Each rng In Selection
lTest = CLng(rng)
If (lTest intCurr + 1) Then

' no sequence, so write what you have
If Len(strlast) = 0 Then
rngTgt.Offset(x, 0) = strFirst
x = x + 1
Else
rngTgt.Offset(x, 0) = strFirst & " - " & strlast
x = x + 1
End If
strFirst = rng
intCurr = CLng(strFirst)
strlast = ""
Else
' it's still a sequence so increase the upper end and
' the comparison value
strlast = rng
intCurr = CLng(rng)
End If
Next

End Sub

For information on installing the code see
Getting Started with Macros and User Defined Functions

http://www.mvps.org/dmcritchie/excel/getstarted.htm



"Mel07" wrote:


I have been unable to figure this one out. I have over 2000 zip codes
in a single column (One 5 digit zip code per row) which are already
sorted in numeric order. I need to put these individucal zip codes
into ranges where possible when zip codes are sequential (i.e.
91714-91734). Is this possible outside of doing this manually because
it's killing me!!! Help.


--
Mel07
------------------------------------------------------------------------
Mel07's Profile: http://www.excelforum.com/member.php...o&userid=32458
View this thread: http://www.excelforum.com/showthread...hreadid=522385


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Mel07
 
Posts: n/a
Default Need to convert list of 5 digit zip codes to ranges where possible


Hi Bruce,
Thanks for the reply - never done one of these forums actually I'm
hoping your input will help me get throught this work faster so
thanks!
Anyway, the zip codes are numeric. If there's an unique, loner zip
code then I would like to have it simply input it again in the column
next to it, column B. I'm going to give your formula a shot. I
appreciate the help greatly! I'll let you know if it works.


--
Mel07
------------------------------------------------------------------------
Mel07's Profile: http://www.excelforum.com/member.php...o&userid=32458
View this thread: http://www.excelforum.com/showthread...hreadid=522385

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
update data validation list with new entries?? cjtj4700 Excel Discussion (Misc queries) 10 December 12th 05 01:00 AM
HOW CAN I CONVERT EXCEL DATA TO BAR CODES? guyinrenton Excel Discussion (Misc queries) 0 September 14th 05 06:02 PM
Extracting Values on one list and not another B Schwarz Excel Discussion (Misc queries) 4 January 7th 05 01:48 PM
convert excel list to pivot table GI Excel Discussion (Misc queries) 0 December 6th 04 06:45 PM
Viewing List of Named Ranges Graham Parkinson Excel Discussion (Misc queries) 2 December 3rd 04 01:30 PM


All times are GMT +1. The time now is 08:41 AM.

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"