View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Mike S[_5_] Mike S[_5_] is offline
external usenet poster
 
Posts: 86
Default Filter ZIP codes into ranges

On 1/26/2012 9:53 AM, ronsmail wrote:
I am working on a project to take a list of ZIP codes (29,133 rows) and
sort it by territory, then find all ZIPs in that territory that are in
sequential order and make a ZIP range from the 2 extremes in the
sequential group.

The logic behind what I want to do goes like this:

Sort by Region code, then by Zone #, then by ZIP code. Find all groups
of ZIP codes sequentially ordered and append the first ZIP in the group
to column X and the last ZIP in the group to Column Y.


I would consider doing everything with arrays to make troubleshooting
easy, and to keep the code fast:

Store the data for region, zone #, and zip in a text file or other
database file that can be read from Excel.

Read the text file into an array: read the whole file into a string the
split it based on the vbcrlf at the end of each line.

Sort the array by region.

Copy the array elements that have the data you're interested in, minus
the no longer needed region field, to a 2nd array.

Erase the first array to save memory.

Sort the 2nd array by zone #.

Copy the array elements that have the data you're interested in, minus
the no longer needed zone #, to a 3rd array.

Erase the second array to save memory.

Sort the 3rd array by zip.

Now it will be easy to check for sequential values and display them in
Excel.

Mike