I have 2 sets of Data range18 and range19. I am trying to use vlookup to get data from range 18 according to look up criteria in range19. It will return the first lookup but after that I get a run-time error '1004': Unable to get the Vlookup property of the WorksheetFunction class. Please help
Code:
Sub getyeardelta()
Dim i As Integer
Dim customer As String
Dim lastrow18 As Long
Dim lastrow19 As Long
Dim range18 As Range
Dim range19 As Range
Dim OctSales As Range
Dim sTotal As String
lastrow18 = Cells(Rows.Count, 1).End(xlUp).Row
lastrow19 = Cells(Rows.Count, 3).End(xlUp).Row
Set range18 = Range("a1:A" & lastrow18)
Set range19 = Range("c1:C" & lastrow19)
Set OctSales = Range("a1:B" & lastrow19)
For i = 2 To lastrow19
customer = WorksheetFunction.CountIf(range18, Cells(i, 3).Value)
If customer > 0 Then
Cells(i, 5).Value = WorksheetFunction.VLookup(Cells(i, 3), OctSales, 2, False)
Else: Cells(i, 5).Value = "New Business"
End If
Next i
End Sub