我正在比较两列中的值,如果满足条件则删除该行。但有时单元格中有文本,我无法让程序忽略或跳过它。这是基本代码:
Sub reorder()
Dim xrow As Integer
Dim incell As Range
Dim xrange As Range
Range("a5").End(xlDown).Select
xrow = ActiveCell.Row
For xrow = xrow To 1 Step -1
If Cells(xrow, 4).Value - Cells(xrow, 5).Value > 1 Then
Rows(xrow).EntireRow.Delete
End If
Next
End Sub
我尝试了各种各样的东西,比如isnumeric函数,但我总是出错或者它无法正常工作。
答案 0 :(得分:1)
现在应该顺利进行:
Sub reorder()
Dim LastRow As Long
Dim i As Long
Dim wS As Worksheet
Set wS = ActiveSheet
With wS
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
For i = LastRow To 1 Step -1
If IsNumeric(.Cells(i, 4).Value) And IsNumeric(.Cells(i, 5).Value) Then
If .Cells(i, 4).Value - .Cells(i, 5).Value > 1 Then
.Rows(i).EntireRow.Delete
Else
End If
Else
End If
Next i
End With
End Sub