VLookup text value and run calculation on adjacent numbers

Panthera

New Member
Joined
Mar 4, 2016
Messages
11
Hi,

I'm trying to run a calculation with numbers in column B based on a VLOOKUP result in column A.

E.g. =IF(ISERROR(VLOOKUP($A5,$A$1:$A$3,1,FALSE)),"",B5-B2)

This will find a match for A5 (Sausage) within the range of A1-A3, if no match the cell is left blank. So far so good.

The substract part is to illustrate what I'm trying to do. B column contains my numbers I want to substract. In this case, if A5 = Sausage and A2 = Sausage my calculation would be correct (-5), but if Sausage had been in A1 the calcuation would be wrong due to the B5-B2 defining the cells.


I thought the "1" or [1,2,3 etc.}, column index, defines where the number(s) I want to use can be found, but how do I tell Excel what i want to do with the numbers? How do I get around not defining the cells but rather let it be based on the VLOOKUP result?... Also played around with =SUM(VLOOKUP... but couldn't get that to work either, so need your help.


Apple5Result in this column
Sausage8
Beer7
Sausage3-5
Beer1
Apple9
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
How about
=IFERROR(B5-VLOOKUP(A5,$A$1:$B$3,2,0),"")
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,935
Members
449,094
Latest member
teemeren

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