If string from range is found then VLOOKUP

DanniiMarie

New Member
Joined
May 21, 2018
Messages
30
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
  6. 2011
  7. 2010
  8. 2007
  9. 2003 or older
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
I want to search a cell for a string in a range. If one of the strings within the range is found, I want to use a vlookup to return a value from a grid. How would I do this with VBA?

Here is an example of what I want to do (I apologize in advance for the wonky formatting on the bottom grid):

VLOOKUP DATA:
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]If this string is found[/TD]
[TD]Use this Value[/TD]
[/TR]
[TR]
[TD]Decals[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]Window POP[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]Planogram[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]Counter Card[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]Billboard[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]DL[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]WIN[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]WP[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]PLAN[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]CC[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]BB[/TD]
[TD]5[/TD]
[/TR]
</tbody>[/TABLE]




















DATA TO SEARCH:
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]Cells to Search[/TD]
[TD="align: center"]Returned Value[/TD]
[/TR]
[TR]
[TD]BB: 25% Off - code: 25OFF (qty: 3500)[/TD]
[TD="align: center"]5[/TD]
[/TR]
[TR]
[TD]Counter Card: Take One[/TD]
[TD="align: center"]4[/TD]
[/TR]
[TR]
[TD]Decals: $12-15 DEAL OF THE DAY[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD][TABLE="width: 310"]
<tbody>[TR="class: grid"]
[TD="width: 310"]Decals: $17/18/19 DEAL OF THE DAY[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD][TABLE="width: 310"]
<tbody>[TR="class: grid"]
[TD="width: 310"]Planogram[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD="align: center"]3[/TD]
[/TR]
[TR]
[TD]BB: 25% Off - code: 25OFF (qty: 7000)[/TD]
[TD="align: center"]5[/TD]
[/TR]
[TR]
[TD][TABLE="width: 310"]
<tbody>[TR="class: grid"]
[TD="width: 310"]WP: AMAZING DEAL $11[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD="align: center"]2[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi,

Change/adjust Cell references/range as needed, formula copied down.

Change "No Match" to "" (Blank) or whatever you want:


Book1
ABCDEF
1If this string is foundUse this ValueCells to SearchReturned Value
2Decals1BB: 25% Off - code: 25OFF (qty: 3500)5
3Window POP2Counter Card: Take One4
4Planogram3Decals: $12-15 DEAL OF THE DAY1
5Counter Card4Decals: $17/18/19 DEAL OF THE DAY1
6Billboard5Planogram3
7DL1BB: 25% Off - code: 25OFF (qty: 7000)5
8WIN2WP: AMAZING DEAL $112
9WP2ABC SomethingNo Match
10PLAN3
11CC4
12BB5
Sheet536
Cell Formulas
RangeFormula
F2=IFERROR(LOOKUP(2,1/SEARCH(A$2:A$12,E2),B$2:B$12),"No Match")
 
Upvote 0
Hi,

Change/adjust Cell references/range as needed, formula copied down.

Change "No Match" to "" (Blank) or whatever you want:

ABCDEF
If this string is foundUse this ValueCells to SearchReturned Value
DecalsBB: 25% Off - code: 25OFF (qty: 3500)
Window POPCounter Card: Take One
PlanogramDecals: $12-15 DEAL OF THE DAY
Counter CardDecals: $17/18/19 DEAL OF THE DAY
BillboardPlanogram
DLBB: 25% Off - code: 25OFF (qty: 7000)
WINWP: AMAZING DEAL $11
WPABC SomethingNo Match
PLAN
CC
BB

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]2[/TD]

[TD="align: right"]1[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"]5[/TD]

[TD="align: center"]3[/TD]

[TD="align: right"]2[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"]4[/TD]

[TD="align: center"]4[/TD]

[TD="align: right"]3[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"]1[/TD]

[TD="align: center"]5[/TD]

[TD="align: right"]4[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"]1[/TD]

[TD="align: center"]6[/TD]

[TD="align: right"]5[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"]3[/TD]

[TD="align: center"]7[/TD]

[TD="align: right"]1[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"]5[/TD]

[TD="align: center"]8[/TD]

[TD="align: right"]2[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"]2[/TD]

[TD="align: center"]9[/TD]

[TD="align: right"]2[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]10[/TD]

[TD="align: right"]3[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]11[/TD]

[TD="align: right"]4[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]12[/TD]

[TD="align: right"]5[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Sheet536

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]F2[/TH]
[TD="align: left"]=IFERROR(LOOKUP(2,1/SEARCH(A$2:A$12,E2),B$2:B$12),"No Match")[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

I was trying to wrap this into a VBA code, but this formula worked in a pinch. Thanks!!!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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