Conditionally Deleting rows with a macro

jkapp

New Member
Joined
Jul 24, 2015
Messages
7
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!

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
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,214,642
Messages
6,120,701
Members
448,980
Latest member
CarlosWin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top