Find zipcode within range and return the Zone name

Raaverok

New Member
Joined
Jan 3, 2023
Messages
5
Office Version
  1. 365
Platform
  1. Windows
So I have a file with multiple zones and want to find my zipcode within the different zones.
The only way I have figured this out is creating a 'help' table where I manually enter the from zipcode and the zone nam.
I want to ensure I don't need the 'help' table, but haven't been able to figure out how to do this.

Example of my table with the zones:

Zone AZone BZone C
2600-26992160-25991000-1119
2920-32192700-29191160-1269
3260-33993220-32591380-1439
3440-34991500-1519
4200-42991940-2159
4700-49993400-3439


My current solution:
FromZone
2600​
Zone A
2920​
Zone A
3260​
Zone A
2160​
Zone B
2700​
Zone B
3220​
Zone B
3440​
Zone B

I am able to do the Xlookup from the current solution, but want to ensure I don't need the current solution to ensure I can prevent the manual work.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi @Raaverok. Thanks for posting on the forum.


Try this array formula:
Dante Amor
ABCDEF
1Zone AZone BZone Cexample zipcode Zone
22600-26992160-25991000-11192163Zone B
32920-32192700-29191160-12691395Zone C
43260-33993220-32591380-14392651Zone A
53440-34991500-15198888Not exists
64200-42991940-21591Not exists
74700-49993400-3439Not exists
8
9
Sh1
Cell Formulas
RangeFormula
F2:F7F2=IFERROR(INDEX($A$1:$C$1,0,MAX(IF($A$2:$C$9<>"",(LEFT($A$2:$C$9,4)+0<=$E2)*(RIGHT($A$2:$C$9,4)+0>=$E2)*(COLUMN($B$1:$D$1))))-1),"Not exists")
Press CTRL+SHIFT+ENTER to enter array formulas.




--------------
I hope to hear from you soon.
Respectfully
Dante Amor
--------------
 
Upvote 0
Hi @Raaverok. Thanks for posting on the forum.


Try this array formula:
Dante Amor
ABCDEF
1Zone AZone BZone Cexample zipcode Zone
22600-26992160-25991000-11192163Zone B
32920-32192700-29191160-12691395Zone C
43260-33993220-32591380-14392651Zone A
53440-34991500-15198888Not exists
64200-42991940-21591Not exists
74700-49993400-3439Not exists
8
9
Sh1
Cell Formulas
RangeFormula
F2:F7F2=IFERROR(INDEX($A$1:$C$1,0,MAX(IF($A$2:$C$9<>"",(LEFT($A$2:$C$9,4)+0<=$E2)*(RIGHT($A$2:$C$9,4)+0>=$E2)*(COLUMN($B$1:$D$1))))-1),"Not exists")
Press CTRL+SHIFT+ENTER to enter array formulas.




--------------
I hope to hear from you soon.
Respectfully
Dante Amor
--------------
Hi Dante,

This works great, thankyou very much!

Do you maybe also have a short explanation on the formula? Want to understand what happens so I can learn from the solution as well.
 
Upvote 1
Do you maybe also have a short explanation on the formula?
Of course, it will not be short because it has several functions.

First, tell you that it is an array formula, this means that it will analyze each of the values found in the arrays and that it will also compare several arrays.

I will divide the formula into parts:
a) From the range $A$2:$C$9<>"" (array 1), it only considers the cells that have a value, the empty ones are not considered because in the next part of the formula a 0 is added to the value, but if you add 0 + "" that raises an error, that's why they shouldn't require the empty cells. All the cells that meet the condition will return a TRUE value.

b) (LEFT($A$2:$C$9.4)+0<=$E2) (array 2), From this range it obtains the left part of each value, as the result of the LEFT function returns a text, it is necessary to add a 0 to convert it to a numerical value, this numerical value is verified to be less than or equal to the value of E2. All the cells that meet the condition will return a TRUE value.

c) (RIGHT($A$2:$C$9,4)+0>=$E2) (array 3), From this range it obtains the left part of each value, as the result of the RIGHT function returns a text, it is necessary to add a 0 to convert it to a numerical value, this numerical value is verified to be greater than or equal to the value of E2. All the cells that meet the condition will return a TRUE value.

d) (COLUMN($B$1:$D$1))))-1) The COLUMN function returns the column number (array 4), in this example it returns 2, 3 and 4.
All the true results of the 3 matrices are compared, which will give us the column number as a result, 1 is subtracted from this column number, which will give us 1, 2 or 3, which in the example are columns A, B or C. If the number was not found in any ZIP code combination, then it returns a 0 minus 1 the result is -1.

e) MAX, The MAX function is used, because only some functions work with matrices, in this example the result can be 0, 1, 2, or 3, so matrix 4 could return something like this: 0, 2, 0, the MAX function takes the maximum value which is 2.

f) INDEX($A$1:$C$1,0, parts a-e), The INDEX function returns the value of a cell, you must tell it the range ($A$1:$C$1), the row number (0) means that no row is moved, and the column number, in this case the column was calculated with the previous functions (parts a,b,c,d and e).
g) IFERROR(parts a-f,"Not exists"), The IFERROR function evaluates the result of the formula if it is not an error, then the result is simply left, but if it is an error, the error occurs when the postal code was not found so the column is -1, since -1 is not in the references of the range of the INDEX function since it only has 1, 2 and 3 as references, then it returns error, then the result is "No exists".
To see how this fomula works or any function works:
1. Select the cell with the formula.
2. On the Formulas tab, in the Formula Auditing group, click Evaluate Formula.
1680364820359.png

3. Click Evaluate button to examine the value of the underlined reference. The result of the evaluation is shown in italics.

___________
I hope this helps.
Cordially
Dante Amor
___________
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,195
Members
453,021
Latest member
pingpong7117

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