Help with deletion of Data in Multiple Sheets

Y

Yossy

I have about 50 sheets in a Workbook. Every time I have to manually delete
certain data from all sheets. I want to delete all data below "Total Number
of Records"

E.g
Total Number of REcords
My Name is PP
Your name is LL
Today's Date..
Total No of Days

Please note that there could be more than four rows of data below "Total
Number of Record". Preferably it should look through all rows e.g.(A20) of
data below the title and delete all. If there is a break space in the rows it
should stop (Cos some data might be below the empty row) and they do not need
to be deleted.

Can you please help me... All help totally appreciated.

Thanks a Great deal
 
P

Per Jessen

Hi

I loop through column A and delete entire rows below "Total Number of
Records" and down to first empty row. Continue with next sheet.

Try this:

Sub DeleteData()
TargetCol = "A"
For Each sh In ThisWorkbook.Sheets
If ActiveSheet.Name <> sh.Name Then
Sheets(sh.Name).Select
End If
Set f = Columns(TargetCol).Find(What:="Total Number of Records")
fRow = f.Row
LastRowToDelete = Cells(fRow, TargetCol).End(xlDown).Row
Range(Rows(fRow + 1), Rows(LastRowToDelete)).Delete
Next
End Sub

Regards,
Per
 
Y

Yossy

please i get error "Compilation code" and it highlighted the " Sub
DeleteData()".

Thanks for helping.
 
P

Per Jessen

Just a guess, did you copied the entire code including the "End Sub"
line.

Regards,
Per
 

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