find语句返回一个范围对象,但是
netAmount = foundsomething.Address.Offset(0, 1).Value
代码为“地址”返回一个“无效的限定词”,但是“ foundsomething”是一个范围对象,因此它应该有一个地址?
Sub getMonthlyNet(ws As Worksheet)
Dim netAmount As Long
Dim month(1 To 12) As String
Dim foundsomething As Range
Dim searchterm As String
month(1) = "january"
month(2) = "febuaray"
month(3) = "march"
month(4) = "april"
month(5) = "may"
month(6) = "june"
month(7) = "july"
month(8) = "august"
month(9) = "september"
month(10) = "october"
month(11) = "november"
month(12) = "december"
For i = 1 To 12
searchterm = month(i)
Set foundsomething = Application.ws.Find(What:="search term", After:=Range("V1"), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If (Not foundsomething Is Nothing) Then
netAmount = foundsomething.Address.Offset(0, 1).Value
Cells(i, 1).Value = foundsomething
Cells(i, 2).Value = netAmount
End If
Next
答案 0 :(得分:0)
netAmount = foundsomething.Offset(0, 1).Value
如果您使用Address
返回String
而不是Range
,并且不能在字符串上调用Offset
。
这:
Application.ws.Find(What:="search term", ...
应为:
Application.ws.Find(What:=searchterm, ...
否则,您要搜索字符串“搜索词”而不是值