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

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

_RKKC_

New Member
Joined
Jun 10, 2016
Messages
8
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

_RKKC_

New Member
Joined
Jun 10, 2016
Messages
8
-_-

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

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,599
Office Version
  1. 365
  2. 2019
  3. 2013
  4. 2007
Platform
  1. Windows
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,191,173
Messages
5,985,096
Members
439,940
Latest member
Kyrad42

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
Top