运行时错误'1004'

时间:2014-11-13 08:14:47

标签: excel excel-vba vba

我正在尝试运行此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

1 个答案:

答案 0 :(得分:2)

问题出在这一行:rws = Range(clLookup, clLookup.End(xlDown)).Rows.Count范围对象属于执行表,而不属于输出表SOA。 这可以通过将代码更改为:

来实现
rws = wbk2.Sheets("SOA").Range(clLookup, clLookup.End(xlDown)).Rows.Count