-1

我在excel中有以下列

Sales Record Number
5100
5275
5310
5355
5357
5359
15
Seller ID: 233

我需要 VBA 代码只显示大于 5000 的行,因此应该删除“销售记录号”、“15”和“卖家 ID”。

我尝试了以下方法:

Sub DeleteRows()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Dim i As Long
    For i = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
        If Not (Range("C" & i).Value < 5000) Then
            Range("C" & i).EntireRow.Delete
        End If
    Next i
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
End Sub
4

1 回答 1

0

If 语句中的调整,它首先检查它是否是数字的,应该可以解决问题吗?

Sub DeleteRows()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Dim i As Long
    For i = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
        If Not IsNumeric(Range("C" & i).Value) Or Range("C" & i).Value < 5000 Then
            Range("C" & i).EntireRow.Delete
        End If
    Next i
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
End Sub
于 2013-09-10T23:14:20.503 回答