VLookup throwing an error - excel

So I have a sheet similar to this:
A B C D E F
1 Name Age Number Gender Player player No.
2 Droid12 11 M Droid12 F3
3 R2D2 13 M C3P0 F12
4 C3P0 12 F Bot13 Y7
5 YVH7707 11 F J34 Z2
6 Bot13 15 M
7 Slim33 13 F
8 ABot43 14 F
9 DBo11 11 M
10 J34 12 M
I am trying to fill in Column C with the player number, if the person in question has one (Imagine that the sheet is thousands of time this large).
I have the following VLookup function in each cell in C (copied down from C1, of course):
=VLOOKUP(A2, $E$2:$F$5, 2,FALSE)
And am getting the result:
#N/A
When I try to step through, I get the error
Sheet1!$A$2 = Droid12: The cell currently being evaluated contains a
constant
Anyone have an idea what I'm doing wrong?
Thank you!
EDIT
I've tried some of these fixes, with no positive results. I tried this in C1-C3:
C2 contains:
=IF(A2=E2, F2, FALSE)
With the result that cell C2 contains the value Droid12
C3 contains:
=VLOOKUP(A2, $E$2:$F$3, 2, FALSE)
and is getting a #N/A error (with the same error:
Sheet1!$A$2 = Droid12: The cell currently being evaluated contains a
constant
The values are all standardized (Trimmed,etc...), and there is definitely a match in the range I'm comparing to, so I really can't see what I'm doing wrong. Anyone ever experience this before?
edit 2
I fixed it, turns out I had Player No. In column E and Player in Column F, so the comparison for some reason was not running correctly. I switched those two entities around, and the VLOOKUP worked fine. Weird, but I'm not complaining. Thanks to everyone who tried to help!

Usually it happens if there is no exact match. Try to use trim and wildcard chars to allow matching to skip spaces. For example:
=VLOOKUP(CONCATENATE("*",TRIM(A2),"*"), $E$2:$F$5, 2,FALSE)

Use this formula:-
=IF(ISERROR(VLOOKUP(A2,E:F,2,FALSE)), "",VLOOKUP(A2,E:F,2,FALSE))
In Simple, formula is
=VLOOKUP(A2,E:F,2,FALSE)
Issue is caused due to the Range, which is mentioned as $E$2:$F$5.
When you are trying to drag the formula for the rest of cells, Range is getting updated wrongly. This is causing issue.
The Cell which doesn't match the actual value then VLOOKUP returns #N/A. To overcome this, I have placed a IF condition to check any error and display empty if fails otherwise the value.

Sometimes the constant error can be avoided if you have the reference data on the furtherest left-hand column on all sheets.
i.e.
Column A1 = Description plus info A2:etc (Sheet 1 and Sheet 2)

The N/A is the result of the name you are looking up not being in the list. This is normal behavior for the VLOOKUP function.
To eliminate the NA being displayed try this formula:
=IF(ISNA(VLOOKUP(A2,$E$2:$F$5, 2, FALSE)),"",VLOOKUP(A2,$E$2:$F$5, 2, FALSE))
This checks to see if the result of the lookup is N/A. If it is, then display blank (""). If the result is not NA then display the lookup value.
One issue with this solution is the lookup will be performed twice on each record that is found (once to check if it is N/A and once again to display the value (although Excel may be optimizing for this situation).

Related

Return the value to the Left where the min is found

As the title states, I am tryong to find the values to the left of where the value returned by min() is found. My Data is laid out as shown below, the columns I want to pull from are TP's so for row Labor (L) = 1, under the LRATC section the TP value should be the value to the left of where the ATC value of 7.5 is found, which would be 10.
I've tried using =INDEX((J5,L5,N5,P5),MATCH(MIN(K5,M5,O5,Q5),(K5,M5,O5,Q5),0)) to create a range for it to use, however this causes a #N/A error seemingly inside the MATCH() operation.
Edit and clarification: in case you want to test things out for yourself, here is the original file Hey! Click Me!. The objective of this post was to have a place online where this problem could be documented as it was not easily found from the usual suspects. I am chiefly trying to troubleshoot the error in the match() call as mentioned above
Well, you did not give data I could copy and test, but I put something together:
K5 L5 M5 N5 O5 P5 Q5
2 22 3 33 4 44 5
and used:
=MATCH(MIN(K5,M5,O5,Q5),(K5:Q5),0)
which returns 1 as in position 1 in the range K5:Q5.
As for the index(), this works, but you need a "+1" to get the values you want:
=INDEX(K5:Q5,,MATCH(MIN(K5,M5,O5,Q5),(K5:Q5),0)+1)
Note the match() is put into the column argument in the index() function.
This now returns the result 22 as it should.
I would restructure the data as this may not be stable (work vertically...) but that is just me.

excel, matching with greater than and lesser than and static values

I am trying to do in Excel what should be done in a database. I have a spreadsheet with raw data and which I am trying to query based on criteria. Given the following example table:
A B C D E F
1 Red up 1 4 dn 5
2 Blu up 5 9
3 Yel dn 1 4
4 Gre dn 5 9
I would like to return the value of column A that meets the criteria of E1 and F1 where E1 is found in column B and F1 is found equal or between the values in columns C and D. In the example, I would like to return "Gre".
I have been pulling my hair out with INDEX and MATCH functions and I can get part of my task done, but have found nothing extensible to solve the total solution.
Thank you in advance for your help!
Please try this...
=IFERROR(INDEX($A$1:$A$4,MATCH(1,INDEX(($B$1:$B$4=$E$1)*($C$1:$C$4<=$F$1)*($D$1:$D$4>=$F$1),),0)),"")
If you don't mind adding headings to your raw data.
You could use this formula:
=DGET($A$1:$D$5,"Field 1",$E$1:$F$2)
A1:D5 being your database.
Field 1 is the field to return values from.
E1:F2 is your criteria (field name and value to look for in that field).
https://support.office.com/en-gb/article/DGET-function-455568bf-4eef-45f7-90f0-ec250d00892e
As noted by #Vityata this won't work for the OP - looking for the value 6 would return a #VALUE error rather than Gre.
A couple of updates would allow it to work:
Updating the formula to: =DGET($A$1:$D$5,"Field 1",$E$1:$G$2)
Updating the table to:
The values in F2 and G2 are calculated as:
="<=" & $H$2 and =">=" & $H$2
This example would then return Yel when 1 is entered in cell H2.
I liked the question, thus I have elaborated a bit on the sktneer's answer.
The reason, it works is because we are looking for truth (a.k.a. 1) in the following formula:
=MATCH(1;
INDEX(($B$1:$B$4=$E$1)*($C$1:$C$4<=$F$1)*($D$1:$D$4>=$F$1););0)
Like this:
Then with an INDIRECT we may achieve the answer:
=INDIRECT(ADDRESSE(I1;1))
If you want it in one formula, it should be like this:
=INDIRECT(ADDRESS(
MATCH(1;INDEX(($B$1:$B$4=$E$1)*($C$1:$C$4<=$F$1)*($D$1:$D$4>=$F$1););0);
1))

Find closest value without going over

I've found similar questions, but they're all at least slightly different from my question, and have been unable to successfully adapt them, so here's a simplified version of my sheet:
A B C D E
1 4 4 17
2 6 10
3 2 12
4 7 19
5 4 23
Column A is full of the integers 1-X. Column B is number of occurrences of Column A, and C is the sum of the values to the left and above. D is a random value between 1 and C5. So far so good. The problem comes with E1. I want it to give the value of A that is to the left of the C value that is the closest to D without going over.
Example: D comes up with the value 17. The closest value to 17 without going over is 12 (C3). Therefore, E equals 3. How would I go about achieving this? I can get the closest value using =INDEX(A$1:A$5,MATCH(MIN(ABS(F1-C$1:C$5)),ABS(F1-C$1:C$5),0)), but it comes to 4, instead of 3. How would I get the closest SMALL value? I'm guessing I have to replace ABS with SMALL, but I'm not sure how to go about doing that.
You can use the "vector form" of LOOKUP for this (see help for LOOKUP function). If you lookup D1 in C1:C5 you'll get exactly the match you want (the largest value that's smaller than or equal to D1) and then you can define the return vector as A1:A5 to get the corresponding value from there
=LOOKUP(D1,C$1:C$5,A$1:A$5)
Note: You'll get an error for D1 values < 4 because in that case there's no value "without going over".
For this to work C1:C5 must be sorted ascending, but that will always be the case in this scenario
Edit: I believe this answers your question, as stated, but if you were looking for the 17th occurrence, in order then shouldn't the result be 4? If that was the case then I think you could still use LOOKUP but column C would have to be set up differently
In E1: =if(C1<=D$1,A1,"") and fill down.
In F1: =max(E1:E5). This is your desired result.

excel 2007 X Y lookup

Good morning. I have been searching for some code either a formula or VBA to lookup values in a table. I have two tables that I am looking to migrate data from the old with the new. Both tables are relatively the same.
A B C D E
1 Store 1234 2345 3456 4567
2 1234 0 5 10 15
3 2345 5 0 20 25
4 3456 10 20 0 35
5 4567 15 25 35 0
It is basically a mileage table with location to location distance. I am looking for a way to take the values from the old table into the new when the row columns dont match up exactly due to new locations added.
I know how to do a vlookup, but that dosent do what Im looking for... I want a way for a formula or vba to something like "find Value in B2 "1234" where it intersects the value in D1 "2345" = D2 "5"
Should be able to do a Index and Match combo to find it. I1 = From, K1 = To you can just type in the locations into those cells and get the range out you want.
=INDEX(A1:E5, MATCH(I1,A1:E1,0), MATCH(K1,A1:A5,0))
Can you implement IF formula to vlookup? In abstract: =IF((vlookup)=something),do this, else)
I would be hapy to look into this issue further, if you could provide complete BEFORE data and expected AFTER data.
Also, maybe =DGET would work for you?
I used this formula slightly modified and it worked fine,
=INDEX($A$1:$G$7, MATCH(B12,$A$1:$A$7,0), MATCH(C12,$A$1:$G$1,0))
the first part of the equation is the entire table including the X and Y coords. the next two parts are the X and Y coords (you can swap these round if you wish)
so the requested information for x and y was put in cells C12 and B12 and all those cells below...
then I used the dollar symbol to fix all the other look up cells, so i could use auto fill, and entered this in E12 (this is where the result will appear.
You can see the table in the attached (or could if I was allowed to attach it). I am looking up B12 (3) in column A then looking up C12 (6) in row 1 and returning the value at the intersection (in this case returns "r").
or there would be an attachment if the stupid web page did not insist on having me obtain a 10 reputation... hopefully you get the idea...

Excel Summing Up

I have this, for example:
ColA ColB
X 1
Y 2
Z 3
X 4
I want to be able to summarize all values in Column B which
Column A=X or
Column A=Y.
The result should be 7 (1+2+4).
I did this:
SUM(IF(COUNTIF(A:A,"X"),VLOOOKUP("X",A:B,2,),"0"), IF(COUNTIF(A:A,"Y"),VLOOOKUP("Y",A:B,2,),"0"))
For some reason, it returns 3. It doesn't adds the second value of X for some reason.
Any ideas why?
Thanks!
=SUMPRODUCT(((A2:A5="X")+(A2:A5="Y"))*(B2:B5))
If you select a portion of the formula and press Ctrl+=, you can see how it is evaluated.
=SUMPRODUCT((({TRUE;FALSE;FALSE;TRUE})+({FALSE;TRUE;FALSE;FALSE}))*(B2:B5))
Now when those two arrays are added together, the TRUE is coerced to a 1 and the FALSE to a zero.
=SUMPRODUCT(({1;1;0;1})*(B2:B5))
The resulting array of 1's and 0's is multiplied by the array from B2:B5.
=SUMPRODUCT({1;2;0;4})
And summed up to 7.
Your formula returns an error (tooo many o’s!) but with VLOOKUPs 3. Since the problem is not with Y, simplify the issue by taking out that part of the formula:
=IF(COUNTIF(A:A,"X"),VLOOKUP("X",A:B,2,),"0")
This results in 1. But so does:
=VLOOKUP("X",A:B,2,)
Hence COUNTIF(A:A,"X") (which returns 2 because there are two instances of X) does not actually help. Replaced with 7, or 103 or 5=5 - no difference.
You are obviously aware that plain vanilla VLOOKUP stops ‘searching’ once it finds the first instance that meets its ‘rules’ but unfortunately inserting a 2 with COUNTIF is not enough to ‘tell’ VLOOKUP “after finding the first match, now go off and find the second as well”.
So an answer to your question as expressed is “Yes. VLOOKUP cannot be made aware of multiple instances with the =COUNTIF function.”

Resources