Using Vlookup with a part of a string (value) - vlookup

I'm trying to look for part of a value
my code is:
=VLOOKUP(LEFT(A3,5),Inventory!A:F,6,FALSE)
A3 = 19017E (second code of a item)
I want to look for 19017 (main code) but get #N/A
Can some body help me?
Many Thanks in advance.

I'll take a stab at submitting a Stack Overflow answer. First time.
I believe it's returning #N/A because the LEFT() function returns a text value, whereas the value in the table of the VLOOKUP() function is a number value.
So, my suggestion is to convert it to a number with the VALUE() function within your VLOOKUP():
=VLOOKUP(VALUE(LEFT(A3,5)), Inventory!A:F,6,FALSE)
If some of your main codes also contain letters, that could be problematic.
That was my solution. Hope that helps.

Related

Avoid duplicate code in Excel IF formula code

I want to avoid duplicate code within excel formulas. Is there a method to repeat a certain code segment?
=IF(A1=1,(A1-B2-C3),(A1-B2-C3)+1)
This would be especially useful when it comes to more complex or longer sections. But: everything must be in ONE formula in ONE cell. Thanks! :-)
EDIT: This is my current code.
=IF(ISNUMBER(SEARCH(".amp",A2)),IFERROR(MID(A2,FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))+1,SEARCH(".html",A2)-FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))-5),""),IFERROR(MID(A2,FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))+1,SEARCH(".html",A2)-FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-",""))))-1),""))
It strips the long ID number out of any URL of a specific CMS. So
FIND("#",SUBSTITUTE(A2,"-","#",LEN(A2)-LEN(SUBSTITUTE(A2,"-","")))
is probably the part which occurs more than once and should be replaced for a code which does not be that duplicate-prone.
EXAMPLE: www.domain.com/path1/path2/this-is-an-article-123-dd-123456789.html --> 1234567890
EXAMPLE: www.domain.com/path1/path2/this-is-an-article-123-dd-1234567890.amp.html ->
1234567890
EXAMPLE: www.domain.com/path1/this-is-an-article-1234567890.html ->
1234567890
In google sheets, you could use REGEXEXTRACT to get what you want:
Formula in B1:
=REGEXEXTRACT(A1,"\d{8,}")
Place the complex common sub-expression in its own cell and refer to that cell.
EDIT#1:
As an alternative, you can use a Named Formula for the sub-expression:
Named Formula
So here is another way of finding the code in Excel:
Here is the formula in Cell B1 which needs to be confirmed by pressing Ctrl+Shift+Enter, then drag it down to apply across board:
{=FILTERXML("<data><a>"&SUBSTITUTE(MID(A1,LARGE(IF(MID(A1,ROW($A$1:INDEX($A:$A,LEN(A1))),1)="-",ROW($A$1:INDEX($A:$A,LEN(A1)))),1)+1,LEN(A1)),".","</a><a>")&"</a></data>","/data/a[1]")}
For the logic behind this formula you may give a read to this article: Extract Words with FILTERXML.
Cheers :)
Ps. it seems that GoogleSheet has out performed Excel in some area already.

Is there a function to check the same value in range?

I am using google sheets and I have a query that if the value in the range is the same then write something. If at least value is other from rest. Can somebody have an idea how to bite this topic?
I was trying to use
=if(A2:C2="Something";"YES";"NO")
=if(A2="Something" AND B2="Something";"YES";"NO")
You could try something like:
if(column(range)*row(range)=countif(range;index(range;0;0);"YES";"NO")
The first part calculates the number of cells in the range, the second calculates the
number of values equal to the value in the first cell.
You can replace the condition by changing index(range;0;0) to for example "Something", if you want to match a literal.
=ARRAYFORMULA(IF(A1:A<>""; IF(COUNTIF(A1:A; A1:A)>1; "yes"; "no"); ))

Using VLOOKUP and IMPORTRANGE to find a match and return one of two potential values

I am trying to change the value of cell B1 depending on if cell A1's value is found in another spreadsheet. If there is a match, I want the cell to say "banned". If A1 isn't found in the other spreadsheet, I want it to say "active'.
I've been playing around with this
=if((VLOOKUP(A3,IMPORTRANGE("https://docs.google.com/xyz","ALL BANNED ACCOUNTS!$G$2:$G$300"),1,false))=A3,"Banned","Active")
and can only get it to return "Banned". If there is no match, it always returns #N/A.
How can I remedy this?
Thanks!
Try changing "FALSE" TO "TRUE". I have found that VLOOKUP behaves erratically, and simply changing the [is_sorted] value helps.
Also, this may or may not make a difference, but you have an extra set of parentheses in your formula:
=if(VLOOKUP(A3,IMPORTRANGE("https://docs.google.com/xyz","ALL BANNED
ACCOUNTS!$G$2:$G$300"),1,false)=A3,"Banned","Active")
This is an old question, but in case it helps someone, since you are using VLOOKUP in one column, the only choices are that it equals A3, or that it isn't found, and if it isn't found, VLOOKUP fails, rather than equaling something else. Therefore, you can use this formula:
=iferror(if(VLOOKUP(A3,IMPORTRANGE("https://docs.google.com/xyz","ALL BANNED
ACCOUNTS!$G$2:$G$300"),1,false)=A3,"Banned","irrelevant"),"Active")
Note that "irrelevant" can be changed to anything, i.e. 0, etc. This result will never happen, as if VLOOKUP isn't equal to the search cell (in this case, A3), it will throw an error. So, "Active" as the result if there's an error will show rather than the value if VLOOKUP is false (since it can't be).
Hopefully this helps someone!

Trying to replace the evaluate function. Having an issue with 1 particular case

I am having a heck of a time trying to figure this out. I'm trying to replace this evaluate function.
<cfoutput>
#evaluate('#qry#.#editVal#')#
</cfoutput>
But I just can't seem to work it out. Both qry and editVal are in the variables scope and when using evaluate it returns a value for instane the value of
#qryVitals.PULSE#
I just can't seem to get the notation right to interpret it. Any help would be greatly appreciated.
#evaluate('#qry#.#editVal#')# is equivalent to #VARIABLES[qry][editVal]#.
As noted by #Leigh, if VARIABLES[qry] is of type query, you have to specify the row number as well, e.g. #VARIABLES[qry][editVal][1]#.

IFERROR STATEMENT WITHIN VLOOKUP

I asked for help on another formula earlier which has lead to another head scratcher for me. I'm sure there is probably a way to use IFERROR somewhere in the formula below, but I can't seem to figure out where. I have a few columns returning #N/A that I just need to be blank.
Everything is working how it should except for the error. I have another formula feeding off of the results of this formula that I need to populate either Y or N based on the results. The #N/A is throwing some of them off.
=IF(J2="",VLOOKUP(B2,Sheet1!B:F,5,FALSE),"PICKED UP")
Just wrap it like this:
=IF(J2="",IFERROR(VLOOKUP(B2,Sheet1!B:F,5,0),"Error msg here"),"PICKED UP")
IFERROR will evaluate the first expression (here, it's the VLOOKUP) and if it returns an error, it will return the second part of the formula, which is Error msg here in this case. Change it to whatever you want to.
Also, you can use 0 to mean FALSE in excel (and 1 to mean TRUE).
=IF(J2="", IF(ISNA(VLOOKUP(B2,Sheet1!B:F,5,FALSE)), "", VLOOKUP(B2,Sheet1!B:F,5,FALSE)),"PICKED UP")