I need to delete all the rows starting with row 2 until the last row with data.
The last row with data will be different all the time.
How can I do this automaticaly by running a macro ?
Please open attached file.
Thank you.
I need to delete all the rows starting with row 2 until the last row with data.
The last row with data will be different all the time.
How can I do this automaticaly by running a macro ?
Please open attached file.
Thank you.
Last edited by iscar_marius; 07-14-2009 at 03:05 AM.
This little script checks column A and finds the last row. It then deletes all rows between 2 and the last row. If the row could be greater than 65,000, then it will need to be modified where you see "Range("A65000"). You can also change the "A" in that statement to check another column for the last row in the table.
Function deleteRowsAfter2()
Dim lastRowInColumnA As Long
lastRowInColumnA = Sheets("Sheet1").Range("A65000").End(xlUp).Row
Rows("2:" & lastRowInColumnA).Rows.Delete
End Function
Thanks for your answer. I need something like this, but to find the last row from all the columns. I don't know exactly if the last row will be in column A,B,C etc.
I found the solution:
![]()
Please Login or Register to view this content.
Hi Iscar,
This should help you out. It finds the last used cell in the worksheet (Sheet1 in this example), and deletes every row from row 2 to that found row.
![]()
Please Login or Register to view this content.
Please help ...
This code does almost everything I need, but if I have values only in row 1, the macro will delete row 1. If I have no value in my worksheet the macro will give me erros code.![]()
Please Login or Register to view this content.
I need row 1 to be intact all the time, I need my code to delete all the rows starting with row 2 to the bottom.
Maybe this:
![]()
Please Login or Register to view this content.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
?None of us is as good as all of us? - Ray Kroc
?Actually, I *am* a rocket scientist.? - JB (little ones count!)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks