2017-03-17 49 views
0

我有一個包含數據列的工作表。我想刪除所有該行的值的任何行小於100刪除行,除非它們包含值> 100

這是我到目前爲止有:

Sub deleterows() 
    Dim lRow As Long 
    Dim iCntr As Long 
    lRow = 900 
    For iCntr = lRow To 1 Step -1 
     If Cells(iCntr, 1) < 100 Then 
      Rows(iCntr).Delete 
     End If 
    Next 
End Sub 

不幸的是,這只是看起來在第一列和將刪除其他列中存在大於100的值的行。有人能幫我看看所有的專欄嗎?

回答

3

您應該能夠查看給定行中的最大值,像這樣編輯您的代碼,請參閱我的意見以獲取詳細信息。

Sub deleterows() 
    Dim lRow As Long 
    Dim iCntr As Long 
    lRow = 900 
    For iCntr = lRow To 1 Step -1 
     ' Check if the maximum value in the columns A:F is less than 100 
     ' If it is, then all of the values are! 
     If Application.WorksheetFunction.Max(ActiveSheet.Range("A" & iCntr & ":F" & iCntr)) < 100 Then 
      Rows(iCntr).Delete 
     End If 
    Next 
End Sub 

當然,您可以將「F」更改爲您希望的任何字母。

+0

感謝Wolfie,這是完美的工作。 – Sherbetdab