Determine missing zip codes from a range for sales territories and determine valid zip for state.

klp325

New Member
Joined
Sep 24, 2019
Messages
5
Originally our sales territories were set up with zip code ranges. Our new requirements are to have each zip code listed, based on a limitation on the new version of the territory tool we use.

So I need to take our existing range lists and convert them, without duplicates, to list each zip code. Each zip code must be a valid zip as well. So far I haven't found a non manual way to do this and I am hoping for your help.

Here is a very small sample of my current data. In the first row below, I need it to spit out 90803 as the missing value. I would also need to know if there are any zip codes between 90804 and 90806.
9080290804
9080690808
9081390815
9170891711
9172391724
9173991741
9176191768
9179191792
9190191903
9190591906
9190891917
9193191935
9194191948
9195091951
9196291963
9197691980
9200392004
9200792011
9201392014
9201892030
9203692040
9205192052
9205492061
9206492072
9207492075
9207892079
9208192086
9209092093
9210192124
9212692140
9214292143

<tbody>
</tbody>
 
Hi, try this tweak

VBA Code:
Sub listzips()

Dim rownum As Long
Dim rownum2 As Long
Dim pcfrom As Long
Dim pcto As Long
Dim pc As Long
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Dim territory As String

Set sh1 = Sheets("Sheet1")
Set sh2 = Sheets("Sheet2")
rownum = 3
rownum2 = 1

Do Until sh1.Cells(rownum, 1).Value = ""

    pcfrom = sh1.Cells(rownum, 2)
    pcto = sh1.Cells(rownum, 3)
    territory = sh1.Cells(rownum, 1)
    
        If pcto < pcfrom Then
        Else
            Do Until pcfrom = pcto + 1
            sh2.Cells(rownum2, 1).Value = territory
            sh2.Cells(rownum2, 2).Value = pcfrom
            pcfrom = pcfrom + 1
            rownum2 = rownum2 + 1
            Loop
        End If
    
rownum = rownum + 1
Loop

End Sub
 
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi, try this tweak

VBA Code:
Sub listzips()

Dim rownum As Long
Dim rownum2 As Long
Dim pcfrom As Long
Dim pcto As Long
Dim pc As Long
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Dim territory As String

Set sh1 = Sheets("Sheet1")
Set sh2 = Sheets("Sheet2")
rownum = 3
rownum2 = 1

Do Until sh1.Cells(rownum, 1).Value = ""

    pcfrom = sh1.Cells(rownum, 2)
    pcto = sh1.Cells(rownum, 3)
    territory = sh1.Cells(rownum, 1)
   
        If pcto < pcfrom Then
        Else
            Do Until pcfrom = pcto + 1
            sh2.Cells(rownum2, 1).Value = territory
            sh2.Cells(rownum2, 2).Value = pcfrom
            pcfrom = pcfrom + 1
            rownum2 = rownum2 + 1
            Loop
        End If
   
rownum = rownum + 1
Loop

End Sub



Thanks for the quick response but I must be doing something wrong. I get the following error.
1593707220991.png
 
Upvote 0
Are your sheets called "Sheet1" and Sheet2"? Rename these to whatever your sheets are called. Sheet1 is the Data, 2 the output

VBA Code:
Set sh1 = Sheets("Sheet1")
Set sh2 = Sheets("Sheet2")
 
Upvote 0
Yes, the sheets are named exactly "Sheet1" & "Sheet2" with capital S and no space between the word and numbers. (No parenthesis)
 
Upvote 0
is that what you want?

TeritoryFromToTeritoryFilledZips
Teritory0019080290804Teritory00190802
Teritory0029080690808Teritory00190803
Teritory0039081390815Teritory00190804
Teritory0019170891711Teritory00290806
Teritory0039172391724Teritory00290807
Teritory0069173991741Teritory00290808
Teritory0079176191768Teritory00390813
Teritory0089179191792Teritory00390814
Teritory0099190191903Teritory00390815
Teritory0099190591906Teritory00191708
Teritory0099190891917Teritory00191709
Teritory0099193191935Teritory00191710
Teritory0139194191948Teritory00191711
Teritory0149195091951Teritory00391723
Teritory0159196291963Teritory00391724
Teritory0169197691980Teritory00691739
Teritory0169200392004Teritory00691740
Teritory0169200792011Teritory00691741
Teritory0069201392014Teritory00791761
Teritory0079201892030Teritory00791762
Teritory0089203692040Teritory00791763
Teritory0229205192052Teritory00791764
Teritory0239205492061Teritory00791765
Teritory0249206492072Teritory00791766
Teritory0259207492075Teritory00791767
Teritory0229207892079Teritory00791768
Teritory0239208192086Teritory00891791
Teritory0249209092093Teritory00891792
Teritory0259210192124Teritory00991901
Teritory0309212692140Teritory00991902
Teritory0319214292143Teritory00991903
Teritory00991905
Teritory00991906
Teritory00991908
Teritory00991909
Teritory00991910
Teritory00991911
Teritory00991912
Teritory00991913
Teritory00991914
Teritory00991915
Teritory00991916
Teritory00991917
Teritory00991931
Teritory00991932
Teritory00991933
Teritory00991934
Teritory00991935
Teritory01391941
Teritory01391942
Teritory01391943
Teritory01391944
Teritory01391945
Teritory01391946
Teritory01391947
Teritory01391948
Teritory01491950
Teritory01491951
Teritory01591962
Teritory01591963
Teritory01691976
Teritory01691977
Teritory01691978
Teritory01691979
Teritory01691980
Teritory01692003
Teritory01692004
Teritory01692007
Teritory01692008
Teritory01692009
Teritory01692010
Teritory01692011
Teritory00692013
Teritory00692014
Teritory00792018
Teritory00792019
Teritory00792020
Teritory00792021
Teritory00792022
Teritory00792023
Teritory00792024
Teritory00792025
Teritory00792026
Teritory00792027
Teritory00792028
Teritory00792029
Teritory00792030
Teritory00892036
Teritory00892037
Teritory00892038
Teritory00892039
Teritory00892040
Teritory02292051
Teritory02292052
Teritory02392054
Teritory02392055
Teritory02392056
Teritory02392057
Teritory02392058
Teritory02392059
Teritory02392060
Teritory02392061
Teritory02492064
Teritory02492065
Teritory02492066
Teritory02492067
Teritory02492068
Teritory02492069
Teritory02492070
Teritory02492071
Teritory02492072
Teritory02592074
Teritory02592075
Teritory02292078
Teritory02292079
Teritory02392081
Teritory02392082
Teritory02392083
Teritory02392084
Teritory02392085
Teritory02392086
Teritory02492090
Teritory02492091
Teritory02492092
Teritory02492093
Teritory02592101
Teritory02592102
Teritory02592103
Teritory02592104
Teritory02592105
Teritory02592106
Teritory02592107
Teritory02592108
Teritory02592109
Teritory02592110
Teritory02592111
Teritory02592112
Teritory02592113
Teritory02592114
Teritory02592115
Teritory02592116
Teritory02592117
Teritory02592118
Teritory02592119
Teritory02592120
Teritory02592121
Teritory02592122
Teritory02592123
Teritory02592124
Teritory03092126
Teritory03092127
Teritory03092128
Teritory03092129
Teritory03092130
Teritory03092131
Teritory03092132
Teritory03092133
Teritory03092134
Teritory03092135
Teritory03092136
Teritory03092137
Teritory03092138
Teritory03092139
Teritory03092140
Teritory03192142
Teritory03192143
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,535
Messages
6,114,198
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top