Delete Rows based on Key Words

_RKKC_

New Member
Joined
Jun 10, 2016
Messages
8
I'm trying to modify some existing code from another macro to do a somewhat similar task. What I want is to check the data on the status column and delete the entire row if the keyword matches. Currently my code appears to delete some of the row, but not columns A or B.

Here is what I have so far:

Data:
UsernameStatusNot UsedNot UsedNot UsedTime
SmithJohn<<not keyword="">></not>---HH:MM:SS
SmithJohn<<keyword>></keyword>---HH:MM:SS<--- Delete this row
SmithJohn<<not keyword="">></not>---HH:MM:SS

<tbody>
</tbody>
Data table format doesn't change.

Code:
Sub DelRows()Dim MaxRow As Long, MyRange, agent As String, r As Long
Application.ScreenUpdating = False


    MaxRow = Cells(Rows.Count, "B").End(xlUp).Row
    MyRange = Range("A1:B" & MaxRow)
    
    For r = MaxRow To 1 Step -1
        If MyRange(r, 2) = "Keyword" Then Rows(r).EntireRow.Delete
    Next r
    
    Range("A1:B" & MaxRow) = MyRange
End Sub

Thank you very much for any assistance you are able to provide.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Apologies, the data table seems to have removed the statuses.

Data:
UsernameStatusNot UsedNot UsedNot UsedTime
SmithJohn<Not Keyword<not keyword="">></not>---HH:MM:SS
SmithJohn<Keyword<keyword>></keyword>---HH:MM:SS<--- Delete this row
SmithJohn<Not Keyword<not keyword="">></not>---HH:MM:SS

<tbody>
</tbody>
Data table format doesn't change.
 
Upvote 0
-_-

Data:
UsernameStatusNot UsedNot UsedNot UsedTime
SmithJohnNot Keyword---HH:MM:SS
SmithJohnKeyword---HH:MM:SS<--- Delete this row
SmithJohnNot Keyword---HH:MM:SS

<tbody>
</tbody>

I swear...it's not my first time posting things to the internet...
 
Upvote 0
Try this, but depending on your dataset....autofilter might be quicker

Code:
Sub DelRows()
Dim r As Long
Application.ScreenUpdating = False
    For r = Cells(Rows.Count, "B").End(xlUp).Row To 1 Step -1
        If Cells(r, 2) = "Keyword" Then Rows(r).Delete
    Next r
Application.ScreenUpdating = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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