我想要获取的是以下代码中空单元格之前的计数:
Dim l As Long
Dim r As Long
For l = 0 To 65866
If IsEmpty(wb.Worksheets("Fund Position(URIL)").Range("A1")) Then
Exit For
Else
r = r + 1
End If
Next l
MsgBox r
上面的代码在执行Automation error
语句时会向Runtime error : -2147221080 (800401a8)
投出一个if
。
请帮忙!
更新
我改变了
If IsEmpty(wb.Worksheets("Fund Position(URIL)").Range("A1")) Then
为:
If IsEmpty(wb.Sheets("Fund Position(URIL)").Range("A1")) Then
它有效。有人可以解释我为什么会这样吗?
答案 0 :(得分:0)
这是你在尝试的吗?
Sub Sample()
Dim wb As Workbook
Dim ws As Worksheet
Dim l As Long
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Fund Position(URIL)")
For l = 1 To 65866
With ws
If IsEmpty(.Range("A" & l)) Then Exit For
End With
Next l
MsgBox l
End Sub