Vlookup function with 2 possible lookupvalue - excel

I'm having some trouble finishing my VLOOKUP function.
My function:
=IFERROR((VLOOKUP($E5,'C:\Users\[Example.xlsx]Sheet1'!$F$7:$G$1048576,2,FALSE)), "Removed")
--> This function works, but not for values with wildcard characters,
in my table array, there are some numerical values with asterisks at the end. For these special numbers, it returns an error (or removed in this case).
Example of table array:
1.1
1.2
1.3*
1.4
1.5*
--> How do I adjust the VLOOKUP to account for regular numbers, and numbers with asterisks (wildcard character)?
--> Note I cannot remove the asterisks from the other workbook, those must stay there
--> I want it to find either of the two values (the one with asterisk, or the one without)
Thank you in advance!

Just for having an acceptable answer:
You can simply check for the value without the * and if that leads to an error, auto-add it like:
=IFERROR(IFERROR(VLOOKUP($E5,'C:\Users\[Example.xlsx]Sheet1'!$F$7:$G$1048576,2,FALSE),VLOOKUP($E5&"*",'C:\Users\[Example.xlsx]Sheet1'!$F$7:$G$1048576,2,FALSE)),"Removed")

try converting the lookup value by a function that returns either numeric and character values, like this:
=IFERROR((VLOOKUP(IFERROR(VALUE($E5);$E5),'C:\Users\[Example.xlsx]Sheet1'!$F$7:$G$1048576,2,FALSE)), "Removed")
P.S.: Sorry my english

Wanted to post the answer for anyone that didn't find it in the comments.
--> Thank you to Dirk Reichel for the answer.
=IFERROR(IFERROR(VLOOKUP($E5,'C:\Users\[Example.xlsx]Sheet1'!
$F$7:$G$1048576,2,‌​FALSE),VLOOKUP($E5&"*",'C:\Users\[Example.xlsx]Sheet1'!
$F$7:$G$1048576,2,FALSE)), "Removed")
The first VLOOKUP looks through to see if there is a value without and asterisk (*), then if there isn't a value, it will go to the value if the first VLOOKUP is incorrect. This leads you to the second value which is another VLOOKUP. The second VLOOKUP searches for a value ending with an asterisk. If it still doesn't find a value, then it will spew out "Removed" as demonstrated by the second IFERROR function.

Related

Lookup / Vlookup not returning correct value

Either I use Lookup or Vlookup, the result is wrong if my lookup value is from a formula.
It is correct if I type the lookup value. I'm expecting 5 as result, which I was able to get in first row because I typed '80%'. However in second row, I get 4 when I reference it to the computed 80%:
But I need to have it look up via a formula, any help please?
While rounding solved the problem for you, it didn't explain where the problem started.
Judging by your examples matching the correct values when typed and wrong if calculated, I conclude the values in A1:B6 are not percentages, but text strings. Using round on those solves your problem, since round converts the string to a number (if it can).
See explanation in this screenshot:

Multiple if search statements in excel?

I am trying to convert text of the month to the number
B2 cell:
BirthMonth_Jan
BirthMonth_Feb
BirthMonth_mar
BirthMonth_Apr
BirthMonth_May
BirthMonth_Jun, ect to december
for example, BirthMonth_Jan will output 1 based on the search of Jan, so i can compare this to another set of numbers
I have this, and tried this, but only works with two if statements, is there anyway i can do this with 12?
=(IF(ISNUMBER(SEARCH("sep",B2)),"9")),(IF(ISNUMBER(SEARCH("aug",B2)),"8")),(IF(ISNUMBER(SEARCH("jul",B2)),"7")),(IF(ISNUMBER(SEARCH("jun",B2)),"6")),(IF(ISNUMBER(SEARCH("may",B2)),"5")),(IF(ISNUMBER(SEARCH("apr",B2)),"4")),(IF(ISNUMBER(SEARCH("mar",B2)),"3")),(IF(ISNUMBER(SEARCH("feb",B2)),"2")),(IF(ISNUMBER(SEARCH("jan",B2)),"1"))
I get #Value!
If i try this, it also doesn't work
=IF(ISNUMBER(SEARCH("dec",B2)),"12",IF(ISNUMBER(SEARCH("nov",B2)),"11")),IF(ISNUMBER(SEARCH("DSH_KnowBe4_BirthMonth_Oc",B2)),"10"))
the second option only works with two but if i add more it throws an error
The questioner is trying to obtain a numeral equivalent to a partial month name extracted from a string. There are any number of examples in stackoverflow and the net generally on this theme. What is special in this case is the partial month name in the target cell, and use of the IF statement. The questioner is right to use search since it is not case-sensitive
Two formula are offered:
Formula 1
=(IF(ISNUMBER(SEARCH("sep",B2)),"9")),(IF(ISNUMBER(SEARCH("aug",B2)),"8")),(IF(ISNUMBER(SEARCH("jul",B2)),"7")),(IF(ISNUMBER(SEARCH("jun",B2)),"6")),(IF(ISNUMBER(SEARCH("may",B2)),"5")),(IF(ISNUMBER(SEARCH("apr",B2)),"4")),(IF(ISNUMBER(SEARCH("mar",B2)),"3")),(IF(ISNUMBER(SEARCH("feb",B2)),"2")),(IF(ISNUMBER(SEARCH("jan",B2)),"1"))
The questioner said "I get #Value!"
This is not a surprise because it is essentially a series of nine, self-contained, unrelated if statements, each separated by a comma. It is an invalid statement.
However, if the if statements were nested, then the formula would work. Something along these lines:
=IF(ISNUMBER(SEARCH("jan",B2)),"1",IF(ISNUMBER(SEARCH("feb",B2)),"2",IF(ISNUMBER(SEARCH("mar",B2)),"3")))
Formula 2
=IF(ISNUMBER(SEARCH("dec",B2)),"12",IF(ISNUMBER(SEARCH("nov",B2)),"11")),IF(ISNUMBER(SEARCH("DSH_KnowBe4_BirthMonth_Oc",B2)),"10"))
So close and yet so far... This statement uses the nested approach mentioned above. There is a major typo for the October search (instead of searching for "oct", the formula searches for "DSH_KnowBe4_BirthMonth_Oc") though this doesn't cause the formula to fail.
Failure is caused by two things:
1) The double bracket following "11")) in the "November" search. There should be zero brackets here.
2) The formula needs an additional closing bracket.
Two other things to note:
1) in the event of a match, the value returned is a string not an integer.
2) there's no provision to return a value in the event of a failure to match.
Working IF statement formula
The following formula, consisting of nested IF statements, works as intended by the questioner.
=IF(ISNUMBER(SEARCH("jan",B2)),"1",IF(ISNUMBER(SEARCH("feb",B2)),"2",IF(ISNUMBER(SEARCH("mar",B2)),"3",IF(ISNUMBER(SEARCH("apr",B2)),"4",IF(ISNUMBER(SEARCH("may",B2)),"5",IF(ISNUMBER(SEARCH("jun",B2)),"6",IF(ISNUMBER(SEARCH("jul",B2)),"7",IF(ISNUMBER(SEARCH("aug",B2)),"8",IF(ISNUMBER(SEARCH("sep",B2)),"9",IF(ISNUMBER(SEARCH("oct",B2)),"10",IF(ISNUMBER(SEARCH("nov",B2)),"11",IF(ISNUMBER(SEARCH("dec",B2)),"12",NA()))))))))))))
Note, the formula uses the NA() function to return #N/A if there is no match.
VLOOKUP alternative
Though the above-mentioned formula works, I find it complicated and inflexible. My preference in situations like this is VLOOKUP. My equivalent formula would be:
=VLOOKUP(RIGHT(B2,LEN(B2)-SEARCH("_",B2)),Sheet2!$A$2:$B$13,2,FALSE)
Using January as an example: BirthMonth_Jan, the formula lookup works like this:
RIGHT(B2,LEN(B2)-SEARCH("_",B2))
1) search for the underline character SEARCH("_",B2),
2) deduct the result from the total length LEN(B2)-SEARCH("_",B2) to give the number of characters to the right of the underline.
3) get all the characters to the right of the underline RIGHT(B2,LEN(B2)-SEARCH("_",B2)). This is the lookup value
4) Create a reference table on another sheet (refer screenshot); lookup this table and return column 2 (the number for that month).
5) If there is no valid result, VLOOKUP automatically returns #N/A.
The reference table on a separate sheet:
Not sure what you are trying to do with the formula but if your "BirthMonth_" text is consistent, you can use :
=MONTH(DATEVALUE("1 "&SUBSTITUTE(A12,"BirthMonth_","")&" 2018"))
Having a view of your data and expected result would help if this is not what you're after.
It is seems just possible what you might want is:
=MONTH(MID(B2,SEARCH("BirthMonth_",B2)+11,3)&0)
Returns a Number.

Assign an Excel function result to a variable within a cell

I'm working on an Excel spreadsheet where I'm using VLOOKUP to get data from another sheet. I have it working, but it's giving me an annoying "0" for blank results. I'd like to incorporate ISBLANK to address it.
My problem is the syntax. I REALLY do NOT want to retype the entire VLOOKUP function for the results if it returns FALSE.
In other words, what I'm trying to avoid doing is this:
=IF(ISNULL(VLOOKUP($A2,Sheet!$B$1:Sheet!$C$200,2)),"",VLOOKUP($A2,Sheet!$B$1:Sheet!$C$200,2))
Ideally, what I want to do is something like this:
=IF(ISNULL(VLOOKUP($A2,Sheet!$B$1:Sheet!$C$200,2)),"",[some variable that stores the result of the VLOOKUP])
Ideas, anyone? Thanks...
Are you open to formatting? You can hide the zeros that way, and therefore keep the formula short.
Highlight the range of the VLOOKUP() results, and go to Formatting, then Custom. Use this format and any 0 will be effectively hidden:
0;-0;;#
It depends whether you're looking up text or numbers.
If you want the result of your expression to be text that you're looking up, it's as simple as wrapping your VLOOKUP with the function T().
So, for text, replace VLOOKUP($A2,Sheet!$B$1:Sheet!$C$200,2,FALSE) with T(VLOOKUP($A2,Sheet!$B$1:Sheet!$C$200,2,FALSE))
If the result of your expression is a number, and your VLOOKUP expression is too complicated to repeat, then you can avoid writing it twice by sneakily using IFERROR. The trick is to make it so that when VLOOKUP returns 0, it makes an error, but otherwise it returns what VLOOKUP returned. And you can do this by taking advantage of some maths: Where x<>0, then 1/(1/x) = x. When x=0, Excel returns #DIV/0!. If we use IFERROR, then we can replace that with an empty string ("")
So, for numbers, replace VLOOKUP($A2,Sheet!$B$1:Sheet!$C$200,2,FALSE) with IFERROR(1/(1/VLOOKUP($A2,Sheet!$B$1:Sheet!$C$200,2,FALSE)),"")
By the looks of it the formula you're asking for is:
=IF(VLOOKUP($A2,Sheet!$B$1:$C$200,2,FALSE)="","",VLOOKUP($A2,Sheet!$B$1:$C$200,2,FALSE))
Edit: The FALSE at the end of the function is so it only finds an exact match. Omitting it, or setting it as True, returns an exact or the next largest value that is less than the lookup value - your list must be sorted in ascending order for that to work.
Note the range reference to the sheet called Sheetis Sheet!$B$1:$C$200 and not Sheet!$B$1:Sheet!$C$200.
Having said that, an easier way is just to hide the 0 returns with number formatting.
Give the cell a custom number format of:
#,##0;-#,##0;;#
The first section #,##0 is the format for positive numbers, the second -#,##0 for negative numbers, the third ;;(no format set) for zeros and the last # for text.

Excel, extra brackets change value of formula?

I am adding the values of several cells from two sheets in excel.
I am using the formulas below to calculate this.
My question is why to two formulas aren't giving the same result? As far as I can tell, the only difference is that the 2nd formula has an extra bracket, which shouldn't change anything?
=SUM(SUMIFS('Ark1'!F15:F75;'Ark1'!E15:E75;{"adgangsareal bolig";"fællesrum bolig"}))+SUM(SUMIFS('Ark2'!F11:F126;'Ark2'!E11:E126;"bolig"))
=SUM((SUMIFS('Ark1'!F15:F75;'Ark1'!E15:E75;{"adgangsareal bolig";"fællesrum bolig"}))+SUM(SUMIFS('Ark2'!F11:F126;'Ark2'!E11:E126;"bolig")))
The latter formula has been working perfectly until now through my Work, but for this specific value i needed to remove the extra bracket.
Jacob is right that its the array bit that is causing the problem, but really the problem is caused by the + sign in an expression containing an array which causes the expression to be evaluated as an array formula. You can fix this by changing the + to ; (or whatever the argument separator character is in your locale).
A simpler example (my locale uses , rather than ;):
=SUM({5,10}+20)
results in 55 (the expression evaluater creates (5+20)+(10+20) using the array expansion rules and then passes {25,30} to SUM) but
=SUM({5,10},20)
results in 35
In your first SUMIFS() you have the criteria listed as an array. When using SUM() around the first SUMIFS() alone, it is returning the sum of the range that meets the first criteria being true in the range, then repeats for the second critera, and then it adds the second SUMIF().
When you add the parentheses, you SUM() the first SUMIF() total for the first array value AND the second SUMIF(), and then you are repeating for the second array. So you are getting that second SUMIF() total added twice essentially.
I believe you want something like this:
=SUM(SUMIF('Ark1'!E15:E75;"adgangsareal bolig";'Ark1'!F15:F75);SUMIF('Ark1'!E15:E75;'Ark1'!F15:F75;"fællesrum bolig");SUMIF('Ark2'!E11:E126;"bolig";'Ark2'!F11:F126))
Try this:
=(87,35+464,71-87,35-464,71)
=87,35+464,71-87,35-464,71
2nd formula results correctly in ZERO, while
1st one results in very small number(-0,0000000000000568434)
Add more decimal places to see it.
I think it is a BUG and has something to do with different type of numbers (decimal, floating,...).

Why does Excel MATCH() not find a match?

I have a table with some numbers stored as text (UPC codes, so I don't want to lose leading zeros). COUNTIF() recognizes matches just fine, but MATCH() doesn't work. Is there a reason why MATCH() can't handle numbers stored as text, or is this just a limitation I'll have to work around?
Functions like MATCH, VLOOKUP and HLOOKUP need to match data type (number or text) whereas COUNTIF/SUMIF make no distinction. Are you using MATCH to find the position or just to establish whether the value exists in your data?
If you have a numeric lookup value you can convert to text in the formula by using &"", e.g.
=MATCH(A1&"",B:B,0)
....or if it's a text lookup value which needs to match with numbers
=MATCH(A1+0,B:B,0)
If you are looking for the word test for example in cell A2, type the following:
=MATCH(""&"test"&"",A2,0)
If this isn't working then try =Trim and =Clean to purify your column.
If =Trim and =Clean don't help, then just use the left 250 characters...
(As the Match Formula may encounter a timeout/overflow after 250 characters.)
=Left(A2, 250)
If you are using names to refer to the ranges, once you have fixed the datatypes also redefine any names which refer to those ranges.

Resources