Cut and Delete Multiple Rows - Criteria Based

revolvermac

New Member
Joined
Jun 8, 2015
Messages
18
Good morning all,

I have a macro that works great for cutting/deleting specific rows, however you have to run it multiple times if there are more than one row that meets the criteria. I want to adjust it so it cuts ALL rows meeting the chosen criteria with one pass. Here's what I have so far:

Sub ClearTerminated()
'
' ClearTerminated Macro
'

'
Dim i As Variant
Dim endrow As Integer
Dim MasterList As Worksheet, Inactive As Worksheet

Set MasterList = ActiveWorkbook.Sheets("Master List")
Set Inactive = ActiveWorkbook.Sheets("Inactive")

endrow = MasterList.Range("A" & MasterList.Rows.Count).End(xlUp).Row

For i = 3 To endrow
If MasterList.Cells(i, "B").Value = "TERM" Then
MasterList.Cells(i, "B").EntireRow.Cut Destination:=Inactive.Range("A" & Inactive.Rows.Count).End(xlUp).Offset(1)
MasterList.Cells(i, "B").EntireRow.Delete
End If
Next

End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi Stridhan,

Thanks for taking the time to respond. I modified the code as per your recommendation, but unfortunately to no result. This change prevents even a single row from being cut/deleted from the "Master List" table. :/
 
Upvote 0
This worked for me !!!
NB:- The word "TERM" must be uppercase in sheet.
Code:
[COLOR="Navy"]Sub[/COLOR] MG11Jun48
[COLOR="Navy"]Dim[/COLOR] i [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Dim[/COLOR] Endrow [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]
[COLOR="Navy"]Dim[/COLOR] MasterList [COLOR="Navy"]As[/COLOR] Worksheet, Inactive [COLOR="Navy"]As[/COLOR] Worksheet


[COLOR="Navy"]Set[/COLOR] MasterList = ActiveWorkbook.Sheets("Master List")
[COLOR="Navy"]Set[/COLOR] Inactive = ActiveWorkbook.Sheets("Inactive")


Endrow = MasterList.Range("A" & MasterList.Rows.Count).End(xlUp).Row


[COLOR="Navy"]For[/COLOR] i = Endrow To 3 [COLOR="Navy"]Step[/COLOR] -1
    [COLOR="Navy"]If[/COLOR] MasterList.Cells(i, "B").Value = "TERM" [COLOR="Navy"]Then[/COLOR]
        MasterList.Cells(i, "B").EntireRow.Cut Destination:=Inactive.Range("A" & Inactive.Rows.Count).End(xlUp).Offset(1)
        MasterList.Cells(i, "B").EntireRow.Delete
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,203,513
Messages
6,055,833
Members
444,828
Latest member
StaffordStag

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