Using formatted text as match function lookup value - excel

My look up array is of format DI-0001. First 3 places are fixed as “DI-“ and next 4 are any number but of fixed length of 4. My look up array is a simple number which is less than 10000. Hence always equals to less than 4 digits. I formatted my lookup value column as “DI-“0000 so as to match the lookup array. But now my match function is breaking down, giving #N/A error. I understand the error, but don’t know how to overcome it.

You are not looking for a number in your look up array so you have to convert the value you are looking up to a string as well, not just format it as string.
=VLOOKUP("DI-"&TEXT(value,"0000"),array,2,0)
Or preferably,
=INDEX(B1:B9,MATCH("DI-"&TEXT(F1,"0000"),A1:A9,0))

Related

Handling errors for "Small" function in excel, when the length of array is less than the array provided

I am trying to consider only the least few in an array of some X number's, i am getting #NUM! error when the function cannot find the length specified.
Example- Small(range,{1,2,3})
here the range of cells that contain numeric value is "range" and {1,2,3} is the 3 smallest number to be considered, what happens if the range has only 2 digits instead of 10.
Any advises will be helpful.
I was expecting a solution where the number can be made adjusted from the numerics available.
Here is the best example i can give
You can use IFERROR
=SUM(IFERROR(SMALL(A7:E7,{1,2,3}),""))
Instead of array entering the formula over three cells, put this in the first cell and copy down three:
=IFERROR(SMALL(range,ROW(ZZ1),"")
Now it will not show the #NUM error if there are less than 3 items in the range
Try:
=SMALL(range,ROW(INDIRECT("1:"&MIN(COUNT(range),3))))

Returning a specific value from a string

2.375;26.375;0.743|98.375;26.375;0.743|98.375;2.375;0.743|2.375;***2.375***;0.743|2.375;26.375;0.743555
I'm trying to return the second value equaling 2.375 after the 3rd "|". What's the best way to do this?
Thanks!
Asuming the string is in cell A1 (and the numbers are always 5 chars in length), the following formula will work:
=MID(A1,FIND(";",A1,FIND("|",A1,FIND("|",A1,FIND("|",A1)+1)+1)+1)+1,5)
OR - to handle any length number you can do this:
=MID(A1,FIND(";",A1,FIND("|",A1,FIND("|",A1,FIND("|",A1)+1)+1)+1)+1,FIND(";",A1,FIND(";",A1,FIND("|",A1,FIND("|",A1,FIND("|",A1)+1)+1)+1)+1)-FIND(";",A1,FIND("|",A1,FIND("|",A1,FIND("|",A1)+1)+1)+1)-1)
This formula will bring the second number after the third | regardless of size.
=--TRIM(MID(SUBSTITUTE(TRIM(MID(SUBSTITUTE(A1,"|",REPT(" ",999)),3*999,999)),";",REPT(" ",999)),999,999))
We can easily make this formula dynamic:
=--TRIM(MID(SUBSTITUTE(TRIM(MID(SUBSTITUTE(A4,"|",REPT(" ",999)),(C1-1)*999+1,999)),";",REPT(" ",999)),(C2-1)*999+1,999))
This will allow you to specify the group and the sequence in that group to return the desired number.

This Excel function extracts an N-digit number from a string. How does it work?

I've attempted to write an Excel function that extracts any N-digit number from a long alphanumeric string. I found a example online in a couple of places (1, 2) that works, but I can't figure out how.
For example, given the string 0xabc_2014528888_abcde_30285_q!, the function should return 2014528888 (assuming N = 10).
I found the following Excel snippet in a couple of places (here for N=10):
=LOOKUP(10^10,MID(A1,ROW(INDIRECT("1:"&LEN(A1)-9)),10)+0)
But I can't understand how it works.
Microsoft's LOOKUP() function documentation says that the first argument to LOOKUP() is the lookup value... how does setting that value to 10^N return N characters?
The INDIRECT() function seems like it's getting the argument 1:21 (in my example string). How is this a valid cell reference? If I enter it in a cell by itself, it doesn't compute anything sensible.
Can anybody explain what this function is doing to extract a numeric sequence?
I'll give this a shot, though there are some parts I'm not sure about.
Basically, what we have here is an array formula that's not being entered as an array - that is, when given a range of values, it will perform its function for each possible value, rather than for the whole range at once.
INDIRECT("$1:$22") returns a reference to all of rows 1 through 22. The ROW function then uses that reference to those rows to return a list or array (this is the part I'm not sure about - I'm not sure how it's creating an array) of numbers {1;2;3;4;5;6;7;8;9;...22}
It then uses MID to return all strings of 10 characters from the source value, using the array of linear numbers from before as the starting points. MID returns another array, {"0xabc 2014";"xabc 20145";"abc 201452";..."e 30285 q!"}. The strings are then forced to perform a mathematical function by the +1. This forces any strings in the array that contain non-numeric characters to return #VALUE! errors, while numeric strings return themselves as a value. We get an array like {#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;#VALUE!;2014528888;#VALUE!;...}
Finally, LOOKUP looks through that array and finds the largest value that is smaller than the first argument - that is, the only result in the array that does not return #VALUE!
I suspect - but cannot state for sure - that the key is using LOOKUP instead of VLOOKUP or any other database function. LOOKUP has two modes of operation - a Vector mode, and an Array mode. I suspect that if used in Array mode, it will force any data fed into its second argument to become an array.

Right(text;5) is not the same as a 5 character text

I have a match function that I could not get working. I boiled it down to the point that it can't find the appropriate match since the values are not the same, apparently.
I have the value 21337 in cell D59. In cell S59 I have the function: Right($d59;5), which displays 21337. However when I enter in a cell: =D59=S59 i get the return FALSE.
I use the Right() function because cells in column D contain concatenated values, where the last 5 values are of importance. For example D60 contains 21337 - 21448, where 21448 is the value I want to match.
Anyone has a clue on what might be the problem?
With no formatting you'll see that 21337 is right aligned - showing this is a number and treated as a number by Excel.
On the other hand Right($d59;5) will show the number left aligned, indicating that the returned value is being treated as text by Excel.
If you try Right($d59;5)*1 Excel will implicitly convert the value back to a number (due to the calculation performed) and both values will be equal.
To be explicit about the conversion, as Brian has pointed out, use VALUE(Right($d59;5)).
If you use "Formula" > "Evaluate Formula", does it show the penultimate Evaluation as21337="21337"
The LEFT(..) function will convert the number to a string, and the string and the number will not equate. Try either =TEXT(D59,"#")=S59 or =D59=N(Left(S59)) to convert in your comparison, or change the code in S59 to =N(Right($D59,5)) to make S59 show a number
(The N(..) function converts a string to a number, returns 0 if Not A Number)

Excel - Return the first negative number of a column

I'm using Excel 2010 and I'm looking for a way to return the first negative number of a column. For instance, I have the following numbers distributed in a column:
1
4
6
-3
4
-1
-10
8
Which function could I use to return -3?
Thanks!
This could be interpreted two ways... If all the numbers are in a single cell (one column) as a string, the MID function can be used. If the numbers are in A1, a formula that could work is this:
=VALUE(MID(A1,SEARCH("-",A1),SEARCH(" ",A1,SEARCH("-",A1))-SEARCH("-",A1)))
If the numbers are each in their own columns (in my example, A3:H3), a different technique must be used:
{=INDEX(A3:H3,1,MATCH(TRUE,A3:H3<0,0))}
Don't type the { } - enter the equation using CTRL+SHIFT+ENTER.
In each case, the formula will return the number -3, which is the first negative number in the series.
Another possibility, avoiding the array formula (which are a big source of performance issues):
=LOOKUP(1;1/(M2:M15<0);M2:M15)
(I assume your numbers are in the M2:M15 range).
This will return the first number matching the "<0" condition. You may use any other condition, including text comparisons.
You may also extract the value of another array corresponding to the matching cell:
=LOOKUP(1;1/(M2:M15<>"OK");T2:T15)
In this example, the first cell containing another string than "OK" will be searched for in the m2:m15 array and the corresponding value in array t2:t15 will be returned.
Please note that the usage of the lookup function should be avoided whenever possible (but in this case, it's very handy !)
(I got the original inspiration for this answer from this post)

Resources