Hello all, I just started doing VBA macros for my job and am running into a problem with this particular code. It is supposed to check Column B for the defined values in the "Case Is" statement. Once it recognizes one of those values I then want it to compare the payment value in Column C to the payment in the cell above it. If they are equal then I would like to delete both rows.
The code is breaking on the second part. It is throwing an error of 'Method range of object _global failed.' for the second range in this line 'If Range("C" & Rw).Value = Range("C" & Rw - 1).Value Then'.
If there's anything I missed let me know. Thanks so much for the help in advance!
The code is breaking on the second part. It is throwing an error of 'Method range of object _global failed.' for the second range in this line 'If Range("C" & Rw).Value = Range("C" & Rw - 1).Value Then'.
If there's anything I missed let me know. Thanks so much for the help in advance!
Code:
Sub DeleteReversals()
Dim delRNG As Range, Rw As Long, LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Rw = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
For Rw = LR To 2 Step -1
Select Case Range("B" & Rw).Value
Case Is = 600, 601, 602, 603, 604, "REV"
If Range("C" & Rw).Value = Range("C" & Rw - 1).Value Then
If delRNG Is Nothing Then
Set delRNG = Range("A" & Rw - 1).Resize(2)
Else
Set delRNG = Union(delRNG, Range("A" & Rw - 1).Resize(2))
End If
End If
End Select
Next Rw
If Not delRNG Is Nothing Then delRNG.EntireRow.Delete xlShiftUp
End Sub