VBA to Remove all rows in Table that contains a speified text string

Kpersen

New Member
Joined
Jan 29, 2018
Messages
25
I have search the forum but found no thread that was able to solve my issue:

I have a spreadsheet named "Files" in which I have a table named "data" where header begins in row 2.
My header in column A2 is "filenumber" and in that column I need to delete entire row where the text "voc" appears as part of the value.

The "voc" value is not just always "voc" only but followed by numbers and other text.
I just need it to delete the entire row if the cell in column A (filenumber) contains "voc"

I tried a macro that would filter by values that contained VOC but there were to many records to make this work with an autofilter.

Any good suggestions?
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
This may not work because of the huge number of implied rows in your Table, but give it a try anyway and let us know how it did...
Code:
Sub DeleteRowsWithVoc()
  With Sheets("Files").ListObjects("Data").DataBodyRange
    .Columns(1).Replace "*voc*", "#N/A", xlWhole, , False, , False, False
    Intersect(.SpecialCells(xlConstants, xlErrors).EntireRow, .Columns).Delete
  End With
End Sub
 
Upvote 0
Hi Rick

This is a good suggestion but the macro does not solely look for errors in column A when deleting the row.
That causes an issue when if a non-VoC row contains and error in another column as those would be deleted as well.

Is there a way to delete the rows based solely on error values in column A?
 
Upvote 0
Hi Rick

This is a good suggestion but the macro does not solely look for errors in column A when deleting the row.
That causes an issue when if a non-VoC row contains and error in another column as those would be deleted as well.

Is there a way to delete the rows based solely on error values in column A?

Untested because I am about to leave the house right now, but give this a try...
Code:
Sub DeleteRowsWithVoc()
  With Sheets("Files").ListObjects("Data").DataBodyRange
    .Columns(1).Replace "*voc*", "#N/A", xlWhole, , False, , False, False
    Intersect([B][COLOR="#FF0000"].Columns(1)[/COLOR][/B].SpecialCells(xlConstants, xlErrors).EntireRow, .Columns).Delete
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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