ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Macro to delete rows based on a condition (https://www.excelbanter.com/excel-worksheet-functions/157179-macro-delete-rows-based-condition.html)

Darrilyn

Macro to delete rows based on a condition
 
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.

Gary''s Student

Macro to delete rows based on a condition
 
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

--
Gary''s Student - gsnu200742


"Darrilyn" wrote:

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.



All times are GMT +1. The time now is 05:09 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com