Macro for deleting all rows in table

Thanks Thanks:  0
Likes Likes:  0
Results 1 to 5 of 5

Thread: Macro for deleting all rows in table

  1. #1
    Board Regular
    Join Date
    Aug 2009
    Location
    SLC, Utah
    Posts
    554
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Macro for deleting all rows in table

     
    I am having trouble deleting all the rows within a table. I have a table with an indefinite amount of rows of data. I want to select the table and delete all the rows of data in order to replace it with another indefinite amount of data. Here is the macro I recorded but it only deletes the first row. Any ideas?

    Code:
    Sub Macro2()
    '
    ' Macro2 Macro
    '
    
    '
        Range("Table8[A]").Select
    Selection.ListObject.ListRows(1).Delete
    End Sub
    Thank you!

    Nicole

  2. #2
    Board Regular
    Join Date
    Jul 2006
    Location
    Brussels
    Posts
    7,944
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Macro for deleting all rows in table

    Perhaps:

    Code:
    Selection.Cells(1).CurrentRange.EntireRow.Delete
    Place your cursor in the tab. Please test this on a COPY OF YOUR FILE.
    Regards,

    Wigi

    http://www.wimgielis.com

    Excel MVP 2011-2014

  3. #3
    Board Regular
    Join Date
    Aug 2009
    Location
    SLC, Utah
    Posts
    554
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Macro for deleting all rows in table

    Just figured it out - I feel really good about myself . I adjusted your code and came up with this:
    Code:
    Sub Macro2()
    '
    ' Macro2 Macro
    '
    
    '
        Range("Table8[A]").Select
    Selection.EntireRow.Delete
    End Sub
    Thanks
    Nicole
    Last edited by nicolewh; Aug 24th, 2009 at 04:41 PM.

  4. #4
    Board Regular
    Join Date
    Jul 2006
    Location
    Brussels
    Posts
    7,944
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Macro for deleting all rows in table

    Well done!

    But this is sufficient:

    Code:
    Sub Macro2()
        Range("Table8[A]").EntireRow.Delete
    End Sub
    Select's only (marginally) slow down macro execution.
    Regards,

    Wigi

    http://www.wimgielis.com

    Excel MVP 2011-2014

  5. #5
    Board Regular
    Join Date
    Aug 2009
    Location
    SLC, Utah
    Posts
    554
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Macro for deleting all rows in table

      
    Thank you so much!

    Nicole

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com