find and delete rows below

V

vikram

Hi All,


Need ur help!

I need a macro which finds a text in column A and deletes 5 rows belo
it but doesnt delete that row which contains text

text is "Accounting Flexfi"

please help thank
 
D

Don Guillett

try this
Sub finddelete()'ONE line
Cells(Columns(1).Find("whattofind").Row + 1, 1).Resize(5, 1).Delete
End Sub
 
D

Don Guillett

What I sent erases the data in the rows. If you want to DELETE the row, just
add .entirerow
Cells(Columns(1).Find("whattofind").Row + 1, 1).Resize(5,
1).entirerow.Delete
--
Don Guillett
SalesAid Software
(e-mail address removed)
Don Guillett said:
try this
Sub finddelete()'ONE line
Cells(Columns(1).Find("whattofind").Row + 1, 1).Resize(5, 1).Delete
End Sub
 
V

vikram

Hi Don,

This macro is doing nothing. When i run it it doesnt do anything
nothing changes
please hel
 
V

vikram

hey don,

i have this text in my file in column a lot of times , so we need
loop function which finds and deletes in this entire sheet
ur macro deletes just onc
 
D

Don Guillett

I don't have time now but look in vbe HELP for FIND or FINDNEXT. There is a
clear example.
 
D

Dave Peterson

Option Explicit
Sub testme01()

Dim FoundCell As Range
Dim FirstAddress As String
Dim FindWhat As String
Dim delRng As Range

FindWhat = "Accounting Flexfi"

With Worksheets("sheet1").Range("a:a")
Set FoundCell = .Cells.Find(what:=FindWhat, _
after:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, lookat:=xlWhole, MatchCase:=False)

If FoundCell Is Nothing Then
'do nothing
Else
FirstAddress = FoundCell.Address
Do
If delRng Is Nothing Then
Set delRng = FoundCell.Offset(1, 0).Resize(5, 1)
Else
Set delRng = Union(delRng, _
FoundCell.Offset(1, 0).Resize(5, 1))
End If
Set FoundCell = .FindNext(FoundCell)
Loop While Not FoundCell Is Nothing _
And FoundCell.Address <> FirstAddress
End If
End With

If delRng Is Nothing Then
'do nothing
Else
delRng.EntireRow.Select
End If
End Sub
 

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