2012-01-29 61 views
0

我運行時出現運行時錯誤91。誰能告訴我我要去哪裏?運行時錯誤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 

回答

2

顯然你的意思wsh.Rows.Count,不Rows.Count

+0

發現錯誤更改以下內容: 設置wsh = ActiveSheet 謝謝! – User124726 2012-01-29 17:58:14

+0

而不是循環,你認爲自動過濾器,然後刪除?它比循環快得多:) – 2012-01-29 18:29:04