VBA code to Vlookup mulitple scenarios and combinations

Wafee

Board Regular
Joined
May 27, 2020
Messages
104
Office Version
  1. 2013
Platform
  1. Windows
Can someone help me with a VBA code for the below scenario.

Sheet1 data.

1. Lookup using AB ID - Vlook up with Column B (Sheet2) and column E (Sheet1) for the status, if the result is NA then,
2. Lookup up between Column H (Sheet2) and Column F (sheet1) and in that if there is a version for that in column J (sheet2) then it also neeeds to be matced with column G (Sheet2) to obtain Status. if the result is again NA then leave it as blank.

to re-iterate AB ID's needs to looked up, if NA then FG ID's needs to be looked up and if FG ID's has a version then it also needs to be combined.

thank you in advance.


Column E - AB ID​
Column F - FG ID​
Column G - FG ID Version​
Column H - Status​
AB325​
FG321​
2​
Initiated​
AB246​
Development​
AB389​
FG441​
6​
Testing​
FG321​
5​
Deployment​
AB457​
FG643​
11​
Development​
AB238​
FG762​
1​
Initiated​

Sheet 2 data (Output - Column K)

Column B - AB IDColumn H - FG IDColumn J - FG ID VersionColumn K - Status
AB238FG7621Initiated
FG3215Deployment
AB246Development
AB457Development
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hello,

Why do you need VBA?

I'm sure there must a simpler formula,

In K1 enter

=IF(ISERROR(MATCH(B1,Sheet1!$E$2:$E$21,0)),INDEX(Sheet1!H:H,MATCH(H1&J1,Sheet1!$F$1:$F$21&Sheet1!$G$1:$G$21,0),0),VLOOKUP(B1,Sheet1!$E$2:$H$21,4,0))

and press CTRL + SHIFT + ENTER, then copy down.

Change row 21 to how ever many rows necessary.
 
Upvote 0
Solution

Forum statistics

Threads
1,216,115
Messages
6,128,923
Members
449,479
Latest member
nana abanyin

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