VBA Code for lookup with multiple criteria

Shankar_Ganesh

New Member
Joined
Jul 31, 2024
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
I need a VBA code to lookup from another sheet in the same workbook with multiple criteria.

sample workbook attached. the data will be more in number and also it is regular day-day activity. hence requesting for vba code to save time.

the vba code should combine a2&b2&c2 in sheet1 and lookup from sheet2 by combining column a-b-c and throw the value available in column F. result should be displayed in sheet1 - h2 cell.
 

Attachments

  • Screenshot 2024-07-31 155304.png
    Screenshot 2024-07-31 155304.png
    20.6 KB · Views: 22
  • Screenshot 2024-07-31 155345.png
    Screenshot 2024-07-31 155345.png
    17.4 KB · Views: 16

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Thank you Mr Kaper. But the version I am using is 2016. Can you please help me out in solving this issue in 2016 version.
 
Upvote 0
Indeed, XLOOKUP is not available in Exccel 2016 but you can use INDEX and MATCH instead
 
Upvote 0
Try this code.
VBA Code:
Sub Macro1()
Dim Lr1&, Lr2&
    
Lr1 = Sheets("SHeet1").Range("A" & Rows.Count).End(xlUp).Row
Lr2 = Sheets("SHeet2").Range("A" & Rows.Count).End(xlUp).Row
With Sheets("Sheet1")
.Range("h2").FormulaArray = "=IFERROR(IF($A2&$B2&$C2<>"""",INDEX(Sheet2!$F$2:$F$" & Lr2 & ",MATCH($A2&$B2&$C2,Sheet2!$A$2:$A$" & Lr2 & "&Sheet2!$B$2:$B$" & Lr2 & "&Sheet2!$C$2:$C$" & Lr2 & ",0)),""""),"""")"
.Range("h2").Copy .Range("h3:h" & Lr1)
End With

End Sub
 
Upvote 0
Solution
Try this code.
VBA Code:
Sub Macro1()
Dim Lr1&, Lr2&
   
Lr1 = Sheets("SHeet1").Range("A" & Rows.Count).End(xlUp).Row
Lr2 = Sheets("SHeet2").Range("A" & Rows.Count).End(xlUp).Row
With Sheets("Sheet1")
.Range("h2").FormulaArray = "=IFERROR(IF($A2&$B2&$C2<>"""",INDEX(Sheet2!$F$2:$F$" & Lr2 & ",MATCH($A2&$B2&$C2,Sheet2!$A$2:$A$" & Lr2 & "&Sheet2!$B$2:$B$" & Lr2 & "&Sheet2!$C$2:$C$" & Lr2 & ",0)),""""),"""")"
.Range("h2").Copy .Range("h3:h" & Lr1)
End With

End Sub
Thanks a lot Mr kvsrinivasamurthy. the problem is solved. I am able to generate the output as required.
 
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,148
Members
452,615
Latest member
bogeys2birdies

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