find text and delete rows.

J

John

need a macro, anyone know how to find a text in the worksheet and delete
range rows from the text it fund. sample: text in column A row 12, I want to
delete rows from rows 3-12 or text in rows 50, I want to delete from rows
50-58. pls help.
 
C

CLR

You would have to define your exact conditions, including what the TEXT is,
or where it may be found, and which rows relative to it's found location to
be deleted. Then a macro can be written to satisfy your requirements.

Vaya con Dios,
Chuck, CABGx3
 
J

John

the text is HEADER in rows 12, so I want to del start from rows 12-rows 1.
and in rows 50 text is MONEY, I want to del rows from 50-58. if the text in
every worksheet at the different rows can it use same macro.
 
C

CLR

Maybe this will help..........it will perform on every sheet in the workbook.
Just be sure to back up your data first and use only a copy for testing.

Sub DeleteCertainRows()
Dim sh As Worksheet
For Each sh In Worksheets
sh.Select
If Range("a50").Value = "money" Then
Rows("50:58").EntireRow.Delete
Else
End If

If Range("a12").Value = "header" Then
Rows("1:12").EntireRow.Delete
Else
End If
Next sh
End Sub


Vaya con Dios,
Chuck, CABGx3
 
J

John

Hi, this only can help for this worksheet. like what I said in every
worksheet the "header" and "money" is in different rows. that I need is a
macro to do (find "header" in the worksheet and del from that rows up to the
first rows and find the "money" then del from that rows to the last rows. so
I only need to keep the rows under"header" to the rows befor "money". is that
clear.
 
D

dksaluki

Assuming you found "money" and/or "header", do you want to delete the
same amount of rows each time? If so, you could do create 2 ranges:
one for HEADER and one for MONEY. then offset them and delete the
rows accordingly. Maybe something like this?

Dim rngMoney As Range
Dim srchMoney As Range

Set srchMoney = Cells.Find("money")
If Not srchMoney Is Nothing Then
Set rngMoney = Range(srchMoney, srchMoney.Offset(0, -9))
End If


and do the same for "header".....
 

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