0

I am getting object required run-time error '424'.

Dim LastRowTwo As Long, TargetRange As Variant, ws As Worksheet

Set ws = Sheets("Reconciliation")


    TargetRange = ws.Range("B2:B" & LastRowTwo)
        With TargetRange
            .Formula = "=IFERROR(VLOOKUP(A2, 'ATP Final'!$G:$G, 1, FALSE), ""N/A"")"
            .Value = .Value
        End With

How can I fix this error?

Jonnyboi
  • 505
  • 5
  • 19

1 Answers1

1

Targetrange is currently declared as a variant and is missing the Set keyword on assignment. This is causing the line TargetRange = ws.Range("B2:B" & LastRowTwo) to implicitly add a .value and load the range's values into a two dimensional array. You want the actual range object with all its methods and properties.

Dim TargetRange As Range
...
set TargetRange = ws.Range("B2:B" & LastRowTwo)
...
Warcupine
  • 4,460
  • 3
  • 15
  • 24
  • @XLmatters This is presumably a snippet and that wasn't copied over, otherwise they never would have made it to the `.formula` line to get the error in the question. – Warcupine Nov 07 '22 at 16:41