Macro to Delete Rows above certain word in column

dariushou

Board Regular
Joined
Feb 17, 2008
Messages
126
Hi there, I'm having a little problem figuring this one out. I have several spreadsheets of cash flows with each set of cash flows starting out in different rows. What i would like to do is delete all of the rows above the cash flows. The cash flows always start below the word total which is always in column A. So if i could create a macro that says delete all rows above the word total when total is found in column A it would work.

Also, within the multiple spreadsheets are multiple worksheets. I would like the macro to automatically go in a folder and open all of the workbooks and delete the rows above the word total for each of the worksheets (the cash flows on each worksheet within the workbook also start on different rows).

Thanks for your time.

Darius
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hi Darius,

Maybe something like this;

Code:
Sub Find_CashFlows()

x = Columns("A").Find("Total").Row

Rows("1:" & x - 1).Delete

End Sub
 
Upvote 0
For multiple Sheets;

Code:
Sub Find_CashFlows()

For i = 1 To Sheets.Count

With Sheets(i)
    x = .Columns("A").Find("Total").Row
    .Rows("1:" & x - 1).Delete
End With

Next i

End Sub
 
Upvote 0
Thanks Schwarzmanne. That worked for one workbook--however i to get a run-time error 91 after the macro is finished. The macro finishes, but then i get an error. Not sure what's that about. Did you know how to open every file within a folder and have the macro process all of the files.

Thanks!!!
 
Upvote 0
Hi Darius,

Not sure whats causing the error to be honest, does the final sheet have a cell "Totals" like the other sheets? Maybe its erroring due to not finding a match, I'm unsure,

As for All workbooks in a folder, I'm afraid thats a bit beyond me for the moment, I'm sure one of the Guru's on the board can suggest something for that though.
 
Upvote 0
Thanks for your help Schwarzmanne!!

Does anyone know how i can go into say 15 files and use Schwarzmanne's macro to delete the rows above the word "total" in column A.

In fact, what i really want to do is have the macro look at the FIRST sheet in all 15 files and delete all of the rows above "Period" when it occurs in column A. I then would like it to look at the rest of the sheets in the workbook and do the same thing, but this time the word in column A is "Total".

Not sure if i have to open the files with the macro and then delete the rows, save, and close.

Any ideas on how to do all of this?

Thanks,
Darius
 
Upvote 0

Forum statistics

Threads
1,214,620
Messages
6,120,554
Members
448,970
Latest member
kennimack

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top