Cliff Crerar
Cliff Crerar

Reputation: 443

Run time error 424 excel vba

Hi I am trying to write this macro to do a vlookup so I don't have formula that keeps calculating and slowing down my work, however I keep getting getting a Run-time error 424 : object required.

Sub matchProgram()

Dim Mrow As Long
Dim Mcol As Long

Table1 = Sh1.Range("A1:A20")
Table2 = Sh2.Range("A1:B20")

Mrow = Sh1.Range("B1").Row
Mcol = Sh1.Range("B1").Column

For Each cl In Table1
  Sh1.Cells(Mrow, Mcol) = Application.WorksheetFunction.VLookup(cl, Table2, 2, False)
  Mrow = Mrow + 1
Next cl

End Sub

Upvotes: 0

Views: 145

Answers (1)

Rory
Rory

Reputation: 34055

You need Set with object variables:

Set Table1 = Sh1.Range("A1:A20")
Set Table2 = Sh2.Range("A1:B20")

(technically, the Table2 will work anyway since VLOOKUP will take an array)

Upvotes: 1

Related Questions