以下子项不起作用:
Sub RemoveAllBelowStr()
Dim SrchRng As Range, i As Integer
Set SrchRng = ActiveSheet.Range("A1:A700")
For i = 0 To SrchRng.rows.Count
If IsEmpty(Cells(i, "A")) Then Exit For 'THIS LINE IS THROWING RUN TIME ERROR
Next i
rows(i & ":" & rows.Count).Delete
End Sub
我收到“应用程序定义的或对象定义的”运行时错误1004。
请建议。
答案 0 :(得分:2)
循环必须从1开始,而不是从0开始。
答案 1 :(得分:1)
问题是:Cells(i, "A")
SrchRange
"A"
所以SrchRng.Cells(i, 1)
纠正指数后:
For i = 1 To SrchRng.Rows.Count
作为替代方案,您可以:
dim cell as range
For each cell in SrchRng
if isempty(cell) then ...