excel VBA,需要Vlookup公式对象[重复]

iszxjhcz  于 2022-11-18  发布在  其他
关注(0)|答案(1)|浏览(183)

此问题在此处已有答案

What is the difference between dim and set in vba(7个答案)
10天前关闭。
我得到对象所需运行时错误'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

如何修复此错误?

zxlwwiss

zxlwwiss1#

Targetrange当前被声明为变量,并且在赋值时缺少Set关键字。这将导致TargetRange = ws.Range("B2:B" & LastRowTwo)行隐式添加.value并将该范围的值加载到二维数组中。您需要实际的范围对象及其所有方法和属性。

Dim TargetRange As Range
...
set TargetRange = ws.Range("B2:B" & LastRowTwo)
...

相关问题