我正在尝试运行此VBA代码,但始终会收到运行时错误“1004”消息
Dim clLookup As Range
Dim clDest As Range
Dim rws As Long
With wbk2.Sheets("SOA")
Set clDest = .Range("J2")
Set clLookup = .Range("G2")
End With
If clLookup.Offset(1, 0) <> vbNullString Then
rws = Range(clLookup, clLookup.End(xlDown)).Rows.Count
Set clDest = clDest.Resize(rws, 1)
End If
clDest.Formula = "=TODAY()-" & clLookup.Address(False, False) & ""
clDest.Value = clDest.Value ' Convert to value
答案 0 :(得分:2)
问题出在这一行:rws = Range(clLookup, clLookup.End(xlDown)).Rows.Count
。
范围对象属于执行表,而不属于输出表SOA。
这可以通过将代码更改为:
rws = wbk2.Sheets("SOA").Range(clLookup, clLookup.End(xlDown)).Rows.Count