Delete rows when column contains a specific character

MikeD

New Member
Joined
Mar 8, 2002
Messages
2
I know how to delete rows if cell in specified column is blank. This time I would like to delete whole row if a cell in a chosen column contains say C for complete or O for outstanding
This message was edited by MikeD on 2002-03-09 18:22
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi Mike


I have many examples of deleting rows based on a criteria here:
http://www.ozgrid.com/VBA/VBACode.htm

Or if you opt for slower method of a loop, you can speed things up a bit by using:

Sub DoIt()
Dim rRange1 As Range, rRange2 As Range
Dim rTheRange As Range
Dim rCell As Range

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

On Error Resume Next
Set rRange1 = Selection.SpecialCells(xlCellTypeConstants, xlTextValues)
Set rRange2 = Selection.SpecialCells(xlCellTypeFormulas, xlTextValues)

If rRange1 Is Nothing Then
Set rTheRange = rRange2
ElseIf rRange2 Is Nothing Then
Set rTheRange = rRange1
Else
Set rTheRange = Range(rRange1, rRange2)
End If

On Error GoTo 0
For Each rCell In rTheRange
If rCell = "C" Or rCell = "O" Then
rCell.EntireRow.Delete
End If
Next

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub


_________________
Kind Regards
Dave Hawley
OzGrid Business Applications
Microsoft Excel/VBA Training
If it's Excel, then it's us!
This message was edited by Dave Hawley on 2002-03-09 18:43
 
Upvote 0
I know how to delete rows if cell in specified column is blank. This time I would like to delete whole row if a cell in a chosed column contains say C for complete or O for outstanding


Many thanks for your help.
 
Upvote 0

Forum statistics

Threads
1,214,415
Messages
6,119,382
Members
448,889
Latest member
TS_711

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