This forumula inconsistency is driving me mad! Please help.

bwoodlee

New Member
Joined
Aug 24, 2011
Messages
3
Okay I have been tasked with the creation of a mileage sheet that will calculate our employees mileage with little effort from the employees.

We have 13 different locations that we drive to frequently. I created a table that contains the distance from each location to any other given location. This table is named array1 in the spreadsheet. I then created two columns in which the employee inputs his starting location and his departing location. There is a final column that contains a formula that searches array1 based on the locations the employee entered in the previous to cells.

The way this formula works is with a vlookup formula nested in vlookup formula. The exact formula is pasted below:
VLOOKUP(C12,array1,VLOOKUP(D12,count,2,FALSE))

So basically it looks at the value in C12 (starting location), then searches for it array1. When it finds it, it does a vlookup for d12 (ending location) in an array named count.

Count is an array that contains all our locations, and their index in array1.
For example in array1, CO is second entry in the array. So in the count array, CO's value is 2.

So the second vlookup will return a value of 2, which will tell the first vlookup to search in the second column and return that data.

This method works wonderfully except for two locations. It returns an #NA when the BF & BR locations are used as the starting destinations. If they are the ending locations it works fine.

This has led me to believe that there is an inconsistency somewhere in my sheet regarding text or number format. But I cannot find one to save my life. I hope this makes sense and it is an easy fix, but I have looked at this thing until I am blue in the face... like this guy :(

I know the details might be somewhat confusing, so I included a link to my sheet so you can get a look at it in action. Any help is hugely appreciated. Thank you.

http://www.bwoodlee.com/mileage.xlsx
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
I have followed many of the techniques on that page, but it still has not solved my issue. As far as I can tell everything that should be number format is number format and everything that should be text format is text format. It is possible I overlooked something, but I do not see it if so.

Thanks for the reply.
 
Upvote 0
looking at your file you have a missing 4th argument for one of the VLOOKUPs - try this version

=IF(ISNA(VLOOKUP(C5,array1,VLOOKUP(D5,count,2,FALSE),FALSE)),0,VLOOKUP(C5,array1,VLOOKUP(D5,count,2,FALSE),FALSE))
 
Upvote 0
Thank you so much Barry! I knew it was something simple that I missed. You have no idea how much I appreciate it. Thank you again!
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,553
Members
452,928
Latest member
101blockchains

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