我有一个应该经常运行的功能:
Public Function FindNumberofhandle(stsmenthandle As String) As Long
Dim r As Long
Dim LastUsedRow As Long
LastUsedRow = Worksheets(2).Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlFormulas).Row
For i = 1 To LastUsedRow
If ActiveWorkbook.Sheets(2).Cells(i, 2).Value = stsmenthandle Then 'ERROR HERE
r = i
End If
Next i
FindNumberofhandle = r
End Function
我收到此错误:
run time error -2147417748(80010108)
Method Cells of Object Worksheet failed
我该怎么做才能解决这个问题?
答案 0 :(得分:1)
我认为你需要更换
ActiveWorkbook.Worksheets(2).Cells(i, 2).Value = stsmenthandle
与
ActiveWorkbook.Worksheets(2).Cells(i, 2).Value = stsmenthandle
表单是图表工作表和工作表的集合,因此如果在引用工作表(2)时获取图表工作表,则属性.cells将无效。
如果有效,请告诉我们,我也很好奇。
忽略具有错误值的单元格:
If Not iserror(ActiveWorkbook.Worksheets(2).Cells(i, 2)) then
If ActiveWorkbook.Worksheets(2).Cells(i, 2).Value = stsmenthandle Then
r = i
End If
End if