Hello everybody!
I'm finishing this macro, which is the last one I had to do, and I decided to use Index and Match to fill in column A using the value in the cell of the corresponding row in column B as a reference.
This data must be obtained from another sheet, and the values I need are also in column A, with the reference values in column B.
But after a lot of trying, I can't get the function to work. Whats wrong? The error occurs in W2.Range just after the parenthesis of the Index function with the following message: "Incorrect number of arguments or invalid property assignment". Was it just a syntax error? Because it seems to me that I filled in the parameters correctly.
I'm finishing this macro, which is the last one I had to do, and I decided to use Index and Match to fill in column A using the value in the cell of the corresponding row in column B as a reference.
This data must be obtained from another sheet, and the values I need are also in column A, with the reference values in column B.
But after a lot of trying, I can't get the function to work. Whats wrong? The error occurs in W2.Range just after the parenthesis of the Index function with the following message: "Incorrect number of arguments or invalid property assignment". Was it just a syntax error? Because it seems to me that I filled in the parameters correctly.
VBA Code:
Sub Material_Code()
Dim W1 As Worksheet
Dim W2 As Worksheet
Dim lastRow As Long
Dim Cell As Range
Set W1 = Sheets("Requests")
Set W2 = Sheets("Catalog")
W1.Activate
lastRow = W.Range("A" & Rows.Count).End(xlUp).Row
For Each Cell In W1.Range("A2:A" & lastRow)
Cell.Offset(0, -1) = Application.WorksheetFunction.Index(W2.Range("A2:A20", Application.WorksheetFunction.Match(Cell, W2.Range("B2:B20", 0)), 0))
Next Cell
End Sub