I am trying to create a VBA code which copies into Sheet "Results" the data in the third column of the below tab when the criteria "Lukas" in the first column and "Apple" in the second column are met. I know this could be done just using a VLOOKUP with multiple criteria but the data source length usually changes and I need the macro to do the check from ROW 2 until the last visible ROW.
According to my example, I should find the values 8 and 5 in the second sheet after running the macro. Below is the code I have been writing which is not working however..
Sub copy()
Dim LastRow As Long
Dim i As Long
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If Worksheets("Sheet1").Cells(i, 1) = "Lukas" And Worksheets("Sheet1").Cells(i, 2) = “Apple” Then
Worksheets("Sheet1").Cells(i, 3).Select
Selection.copy
Sheets("Sheet2").Select
Range(Cells(1, 1)).PasteSpecial xlPasteValues
End If
Next i
End Sub
Apple
– urdearboy