+ Reply to Thread
Results 1 to 8 of 8

delete rows using macro

  1. #1
    Forum Contributor iscar_marius's Avatar
    Join Date
    12-19-2008
    Location
    germany
    MS-Off Ver
    2000 and 2003
    Posts
    221

    delete rows using macro

    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.
    Attached Files Attached Files
    Last edited by iscar_marius; 07-14-2009 at 03:05 AM.

  2. #2
    Registered User
    Join Date
    07-13-2009
    Location
    Salt Lake City, Utah
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: delete rows using macro

    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

  3. #3
    Forum Contributor iscar_marius's Avatar
    Join Date
    12-19-2008
    Location
    germany
    MS-Off Ver
    2000 and 2003
    Posts
    221

    Re: delete rows using macro

    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.

  4. #4
    Forum Contributor iscar_marius's Avatar
    Join Date
    12-19-2008
    Location
    germany
    MS-Off Ver
    2000 and 2003
    Posts
    221

    Re: delete rows using macro

    I found the solution:

    Please Login or Register  to view this content.

  5. #5
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: delete rows using macro

    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.

  6. #6
    Forum Contributor iscar_marius's Avatar
    Join Date
    12-19-2008
    Location
    germany
    MS-Off Ver
    2000 and 2003
    Posts
    221

    Re: delete rows using macro

    Quote Originally Posted by Paul View Post
    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.
    Thank you, looks good

  7. #7
    Forum Contributor iscar_marius's Avatar
    Join Date
    12-19-2008
    Location
    germany
    MS-Off Ver
    2000 and 2003
    Posts
    221

    Re: delete rows using macro

    Please help ...

    Please Login or Register  to view this content.
    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.
    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.

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: delete rows using macro

    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 the icon 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!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1