I\'m looking to make the sorting of hundreds of envelopes by USPS postal zones easier. The difficulty is in having to manually sort them for each of the 8 US zones, based on the
Splitting out every possible zip code seems viable but might be ‘overkill’ (though might be useful to detect errors). I’m assuming that a code not in the range mentioned is (a) not valid but (b) does not require to be flagged in any way, so for example 099
will either never arise in practice (unless the tables are updated) or can ‘safely’ be treated as 098
.
This is to make it possible to consider only one value for each band (before a change in Zone), conveniently your ZIP_BEG
ones, in conjunction with an inexact VLOOKUP. The syntax for VLOOKUP is:
VLOOKUP(lookup_value,table_array,col_index_num,range_lookup)
where the fourth parameter (range_lookup) is optional. Forgetting it or setting it to TRUE (or 1
) by mistake has caused much grief but may be very suitable here.
To quote:
If TRUE or omitted, an exact or approximate match is returned. If an exact match is not found, the next largest value that is less than lookup_value is returned. The values in the first column of table_array must be placed in ascending sort order; otherwise, VLOOKUP may not give the correct value.
(It does a binary search, so needs to know which direction is more and which less).Your values should already be in the required order, so a formula such as:
=VLOOKUP(A2,ZIPUP,2)
somewhere in the same workbook should be sufficient, where the value to be looked up (first three digits of destination Zip) is assumed to be in A2 and ZIPUP
is the name of a workbook-scoped range of ZIP_BEG
in one column and Zone
in the matching rows in the column immediately to the right of that.
Given the initial assumptions, the entire ZIP-BEG
list is not required (108 ‘ranges’) as, using only the limits, 74 are sufficient (and should be quicker).
If not aggregating the bands in that way, beware of formatting as 005
is not the same as 5
and that distinction is relevant to =VLOOKUP. You have used =LEFT and =RIGHT to extract your lists and these text functions return strings, though here I would prefer number formatting myself. (I split the ranges with Text to Columns.)