-4

Is it possible to use the RIGHT function with XLOOKUP?

I have the following formula that refuses to work

=XLOOKUP(RIGHT(A2, 3), Sheet1!$A$3:$A$200, Sheet1!$B$3:$B$200, "")

Any alternatives welcome!

15
  • 4
    Did it say you "I refuse" or how was it? Commented Jul 18 at 10:02
  • Please clarify your question by editing it so others can reproduce your problem. Suggest you read the HELP pages for information as to How to Ask a Good Question, and How to create a Minimal, Complete, and Verifiable example. Commented Jul 18 at 10:06
  • What error are you getting? Because it works for me. Also for this to work, check what is the value of RIGHT(A2, 3). This value has to be present in Sheet1!$A$3:$A$200 without any trailing or leading places. It has to be exact. Commented Jul 18 at 10:24
  • 1
    Find the cell that you think is the same, e.g., Sheet1!A5, and try the following formula: =RIGHT(A2, 3)=Sheet1!A5. Maybe share what exactly is in the cells. Commented Jul 18 at 11:06
  • 3
    @cdfj, in that case you are comparing a string against a number most likely! Try: =XLOOKUP(--RIGHT(A2, 3), Sheet1!$A$3:$A$200, Sheet1!$B$3:$B$200, "") Commented Jul 18 at 11:25

2 Answers 2

3

To ensure your data and the search pattern, use

=TEXTJOIN(",",TRUE,CODE(MID(RIGHT(A2,3),SEQUENCE(3),1)))=
  TEXTJOIN(",",TRUE,CODE(MID(Sheet1!A5,SEQUENCE(LEN(Sheet1!A5)),1)))

where 'Sheet1!A5' is expected cell matches the search pattern.

The formula

=TEXTJOIN(",",TRUE,CODE(MID(str,SEQUENCE(LEN(str)),1)))

provides the list of codes for the given string 'str'.

UPD

If you have numbers in the sought range, use

=XLOOKUP(RIGHT(A2, 3), TEXT(Sheet1!$A$3:$A$200,"#"), Sheet1!$B$3:$B$200, "")

Or, vise versa:

=XLOOKUP(VALUE(RIGHT(A2, 3)), Sheet1!$A$3:$A$200, Sheet1!$B$3:$B$200, "")
Sign up to request clarification or add additional context in comments.

3 Comments

That formula returns TRUE
Thanks @rotabor =XLOOKUP(RIGHT(A2, 3), TEXT(Sheet1!$A$3:$A$200,"#"), Sheet1!$B$3:$B$200, "") solved the problem!
It's important to provide full information including data set(s) or data samples.
3

Looking at all the comments I'm pretty sure OP is comparing text against numbers.

enter image description here

Formula in D2 as an example:

=XLOOKUP(--RIGHT(A2,3),A4:A5,B4:B5,"")

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.