尝试查找时的运行时错误91

时间:2012-01-29 17:53:02

标签: vba excel-vba excel-2007 runtime-error excel

运行时遇到运行时错误91。谁能告诉我哪里出错了?

Sub deletingstuff2()

Application.ScreenUpdating = False
Dim i As Long, lngEndRowInv As Long, wsh As Worksheet
Set wsh = ThisWorkbook.ActiveSheet
i = 1
lngEndRowInv = wsh.Range("C" & Rows.Count).End(xlUp).Row **<<ERROR IS HERE**

While i <= lngEndRowInv
If Cells(i, "C") = "Blue" Then
Cells(i, "C").EntireRow.Delete
ElseIf Cells(i, "C") = "Diamond" Then
Cells(i, "C").EntireRow.Delete
i = i - 1
lngEndRowInv = lngEndRowInv - 1
End If
i = i + 1
Wend
end sub

1 个答案:

答案 0 :(得分:2)

显然你的意思是wsh.Rows.Count,而不是Rows.Count