+ Reply to Thread
Results 1 to 6 of 6

Clear an Excel table with a Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    03-13-2019
    Location
    Milwaukee, WI
    MS-Off Ver
    2016
    Posts
    4

    Clear an Excel table with a Macro

    I am looking for way to clear an Excel Table with a macro. The table is a named table in Excel format. I am using this to download and clean up data. There are some calculated columns at the end. I just want to be able to copy into a blank table. I have functionality to automatically clean the data, but I cannot seem to get it to clear all the way to the bottom of the table. The number of rows will be variable.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,290

    Re: Clear an Excel table with a Macro

    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    03-13-2019
    Location
    Milwaukee, WI
    MS-Off Ver
    2016
    Posts
    4

    Re: Clear an Excel table with a Macro

    Okay, Good suggestion. I copy the data in columns A:N from a large database. It usually is several hundred rows of data. Columns O:R are calculated. I run a quick macro to clean the data and copy it then I post it in the page for that institution. All I am looking for here is a macro to clear this table called "TableRadBadges" so it is ready for my next import. I do not want it to delete the formulas in columns O:R or the titles. I was able to find information to do this for a range but not for data in Excel table format.
    Attached Files Attached Files

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,290

    Re: Clear an Excel table with a Macro

    Here you go:

    Option Explicit
    
    Sub sClearTable()
    
    With Sheets("Sheet1").ListObjects("TableRadBadges").DataBodyRange
        .Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
        .Offset(0)(1, 1).Resize(1, 14).ClearContents
    End With
    
    End Sub
    
    Sub sClearTable_Test()
    
    With Sheets("Sheet1").ListObjects("TableRadBadges").DataBodyRange
    
    '    Debug.Print .Rows.Count
    '    Debug.Print .Offset(0).Address
    '    Debug.Print .Offset(1).Address
    '    Debug.Print .Offset(1).Resize(.Rows.Count - 1).Address
    '    Debug.Print .Offset(0)(1, 1).Address
    '    Debug.Print .Offset(0)(1, 1).Resize(1, 14).Address
    
    ' the next two rows are what you need
        .Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
        .Offset(0)(1, 1).Resize(1, 14).ClearContents
    End With
    
    End Sub

  5. #5
    Registered User
    Join Date
    03-13-2019
    Location
    Milwaukee, WI
    MS-Off Ver
    2016
    Posts
    4

    Re: Clear an Excel table with a Macro

    Thank you very much. You are awesome. I could not seem to get it to work on a formatted table. Your code works and it is very much appreciated.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,290

    Re: Clear an Excel table with a Macro

    You're welcome. Thanks for the rep.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro to Clear Cells and form a table out of it
    By Nikhil76 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-19-2018, 08:19 PM
  2. Replies: 9
    Last Post: 09-05-2017, 06:14 PM
  3. Clear List Macro for Data Validation, Multiple Lines in table
    By gedwards913 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-01-2014, 04:42 PM
  4. Pivot Table Macro Help - Clear ColulmnFields
    By jtwusmc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-04-2013, 11:25 AM
  5. Clear Word Table Row from Excel VBA
    By natefarm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-26-2013, 06:07 PM
  6. Macro to clear all filters in a table
    By quantumag in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-07-2013, 05:39 PM
  7. Macro to clear then reinsert pivot table datafield
    By Fullam in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-21-2006, 07:40 AM

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