Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to find and delete text

Status
Not open for further replies.

jonschofield

Technical User
Joined
Dec 16, 2002
Messages
13
Location
GB
I know this may sound simple but I'm trying to write a macro for Excel that will find rows in a workbook containing certain strings of text and delete all those rows.

Anyone got any ideas, hints or tips?
 
I have used this macro to find part of a string to delete the whole row. This particualr macro looks for the first six letters SrvDsk and deletes the entire row. I didn't need to look for duplicates as such if there are duplicates, then this macro will skip the second row. A simple way to deal with duplicates would be to include
R=R-1 just before Next R

Sub ParseData()
Dim R As Long
Dim C As Range
Dim N As Long
Dim Rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

If Selection.Rows.Count > 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If

For R = Rng.Rows.Count To 1 Step -1

Range("B" & R).Select
lft = Left(Selection.Value, 3)

If lft = "SrvDsk" Then
Rng.Rows(R).EntireRow.Delete

End If

Next R

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub

 
I've tried running this macro but it doesn't seem to delete any rows where the specified string is found (which I have changed to "list", since I want to delete all the rows which start with "list". Any feedback would be appreciated.
 
I guess I neglected to mention that this looks for the string in column B

In the following statement change B to which ever column your string is in.
Range("B" & R).Select
I don't particularly care about apathy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top