Search a range of cells in another tab and return a value

andrebooyzen

New Member
Joined
May 30, 2023
Messages
19
Office Version
  1. 365
Platform
  1. Windows
Hi Guys

I want to populate a cell with a value picked up from a matched value in another range of cells in a different tab. e.g the cell I want to populate is B2. The tab name to search is in B1. The value I want to search for is in cell A2. The range to search in the other tab is A1:C4. If it finds a match for A2 in the search range in the other tab (A1:C4) it should return the rightmost 3 characters - but only if the 2nd and 3rd last character in the searched cell is an "XM".

Cells I am wanting to populate....
ABC
tab nametab name
JohnI WANT TO POPLULATE THIS CELL
Peter

This is what the other tab looks like. I want to search a range of cells (A1:C4) and if it finds a match for the value in A2 (John) then return last 3 characters in cell - only if the 2nd and 3rd last characters in the cell are "XM". In the range below it should search A1 to C4. It should find a match for "John" and if it also finds XM in the same cell then it should return the last 3 characters in the cell. In this case it should find a match in cell C2 and return "XMP".

ABC
0900
John
Sheila
0930
Joe
Peter
0820
Susan
Ian
1100
Peter
Andrew
1100
John
Vic
1000
John
Frank
XMP
1200
Ian
Sue
1220
Val
Fiona
1500
Joseph
Cal
1400
Andy
Brian
1700
Bella
Jacky
1600
Rochelle
Burt

Any help would be apprecaited. :)
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Give this a try. For the moment I have assumed at most one cell in the relevant sheet would meet the conditions.
I have changed the sample data a bit.

andrebooyzen.xlsm
ABC
10900 John Sheila0930 Joe Peter0820 Susan Ian
21100 Peter Andrew AXM1100 Sam Vic XMZ1000 John Frank XMP
3
4
Sheet2


andrebooyzen.xlsm
AB
1Sheet2
2JohnXMP
3Peter 
4VicXMZ
Sheet1
Cell Formulas
RangeFormula
B2:B4B2=LET(c,TOCOL("|"&SUBSTITUTE(INDIRECT("'"&B$1&"'!A$1:C$4"),CHAR(10),"|")&"|"),LEFT(RIGHT(FILTER(c,ISNUMBER(SEARCH("|"&A2&"|",c))*(LEFT(RIGHT(c,4),2)="XM"),""),4),3))
 
Upvote 0
Give this a try. For the moment I have assumed at most one cell in the relevant sheet would meet the conditions.
I have changed the sample data a bit.

andrebooyzen.xlsm
ABC
10900 John Sheila0930 Joe Peter0820 Susan Ian
21100 Peter Andrew AXM1100 Sam Vic XMZ1000 John Frank XMP
3
4
Sheet2


andrebooyzen.xlsm
AB
1Sheet2
2JohnXMP
3Peter 
4VicXMZ
Sheet1
Cell Formulas
RangeFormula
B2:B4B2=LET(c,TOCOL("|"&SUBSTITUTE(INDIRECT("'"&B$1&"'!A$1:C$4"),CHAR(10),"|")&"|"),LEFT(RIGHT(FILTER(c,ISNUMBER(SEARCH("|"&A2&"|",c))*(LEFT(RIGHT(c,4),2)="XM"),""),4),3))
Thanks a lot Peter. Tried this and triple checked I have the formula correct....but I get a SPILL! error...
There could be more than one cell meeting the conditions, but I only need to pick up the first or last occurrence.
 
Upvote 0
There could be more than one cell meeting the conditions,
That wasn't mentioned before so I didn't allow for it. :)
Try this

andrebooyzen.xlsm
ABC
10900 John Sheila0930 Joe Peter0820 Susan Ian
21100 Peter Andrew AXM1100 Sam John XMZ1000 John Frank XMP
Sheet2


andrebooyzen.xlsm
AB
1Sheet2
2JohnXMZ
3Peter 
4SamXMZ
Sheet1
Cell Formulas
RangeFormula
B2:B4B2=LET(c,TOCOL("|"&SUBSTITUTE(INDIRECT("'"&B$1&"'!A$1:C$4"),CHAR(10),"|")&"|"),INDEX(LEFT(RIGHT(FILTER(c,ISNUMBER(SEARCH("|"&A2&"|",c))*(LEFT(RIGHT(c,4),2)="XM"),""),4),3),1))
 
Upvote 1
Solution

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top