运行时错误“1004”

我试图运行这个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 

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

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