2017-03-17 50 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