Macro - delete entire row which contain a specific text

  • Thread starter Dileep Chandran
  • Start date
D

Dileep Chandran

To the masters of the excel:

I have the following macro. How can I change the range to look up form
(a:a) to multiple ranges. say like Column A, B, C, X, Y and Z?


Sub DeleteRows()
Dim myWord As String
Dim FoundCell As Range
Dim wks As Worksheet


Set wks = Worksheets("sheet1")


myWord = "Test"


With wks.Range("a:a")
Do
Set FoundCell = .Cells.Find(what:=myWord, _
after:=.Cells(.Cells.Count), _
lookat:=xlWhole, MatchCase:=False)
If FoundCell Is Nothing Then
Exit Do
Else
FoundCell.EntireRow.Delete
End If
Loop
End With

Can anyone help me?

Thanks
-Dileep Chandran


End Sub
 
D

Dileep Chandran

Sorry a small change:

It should delete the rows, only when all the columns (Column A, B, C,
X, Y and Z) contains the specified text and not if any one of the
columns contains the specified text ("Test").

-Dileep
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top