return multiple cell values based on multiple criteria

MMM_84

New Member
Joined
Jan 13, 2021
Messages
18
Office Version
  1. 365
Platform
  1. Windows
Looking for a vba that returns different cell values based on multiple matching criteria. I was using below, but that one works only with 2 cells matching value.

Test Worksheet is the main one, that contains table with headers (A1:F50)
Result Worksheet has to return cell values from "test" wsh columns A, C and D onto the table A2:G50 based on

"reslust" wsh range A2:A50 value to be equal to "test" wsh range E2:E10
"reslust" wsh range A1:G1 value to be equal to "test" wsh range B2:B50


Option Explicit
Sub FindValues()
Dim lookUpSheet As Worksheet, updateSheet As Worksheet
Dim i As Long, lastRow as Long
Dim sResult As String, sKey As String
Set lookUpSheet = Worksheets("Test")
Set updateSheet = Worksheets("Result")
sKey = updateSheet.Range("A2").Value & updateSheet.Range("E1").Value ' should be the range A2:A50 and range A1:G1, that matches below range '
with lookUpSheet
lastRow = .Cells(.Rows.Count, 2).End(xlUp).Row
For i = 2 To lastRow
If .Cells(i, 5).Value & .Cells(i, 2).Value = sKey Then
sResult = sResult & vbNewLine & .Cells(i, 1).Value & vbNewLine _
& .Cells(i, 3).Value & vbNewLine & .Cells(i, 4).Value
End If
Next i
end with
updateSheet.Cells(2, 2).Value = mid(sResult,2) ' the range A2:G50 should be updated, instead of one single cell '
End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach screenshots (not pictures) of your two sheets. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0

Forum statistics

Threads
1,215,071
Messages
6,122,963
Members
449,094
Latest member
Anshu121

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