Macro to delete rows based on a condition

G

Guest

I am trying to write a macro that will delete rows from a spreadsheet based
on a condition. I pull information from another program into excel for
budget purposes and it throws the company names in the header in column form,
so based on how many companies I pull in the number of rows that will need to
be deleted will be changing. I have text that starts after the companies
names (Trial Balance) and I want this to always start on A7. My question is
how do I tell excel to look for the word Trial Balance in Column A and then
delete everything that comes before it? Any help is greatly appreciated.
 
G

Guest

This sub looks for the words Trial Balance in column A. It will delete all
rows above the found row:

Sub zero()
Set r = ActiveSheet.UsedRange
nLastRow = r.Rows.Count + r.Row - 1
killer = 0

For i = nLastRow To 1 Step -1
If killer = 1 Then
Cells(i, 1).EntireRow.Delete
End If
If Cells(i, 1).Value = "Trial Balance" Then
killer = 1
End If
Next
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