Vlookup question

zpierucci

New Member
Joined
Sep 5, 2019
Messages
42
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
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
try making this change
Code:
Set OctSales = Range("a1:B" & lastrow1[COLOR=#ff0000]8[/COLOR])
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,516
Messages
6,119,978
Members
448,934
Latest member
audette89

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