Results 1 to 8 of 8

Adding a Table Row Doesn't Work Immediately After Deleting All Rows

Threaded View

  1. #1
    Forum Contributor
    Join Date
    04-23-2014
    Location
    United Kingdom
    MS-Off Ver
    Microsoft 365
    Posts
    149

    Adding a Table Row Doesn't Work Immediately After Deleting All Rows

    I have a procedure that deletes all rows in a table, and I have another that adds a row. The problem is when I run DeleteAllRows and then AddRow immediately after, it doesn't work the first time. It only works on the second run.

    Why is this and what is the solution?

    Sub DeleteAllRows()
    
        With Range("Table1").ListObject
            
            If Not .DataBodyRange Is Nothing Then
                .DataBodyRange.Delete
            End If
            
        End With
        
    End Sub
    Sub AddRow()
    
        Dim ws As Worksheet
        Dim tbl As ListObject
        
        Set ws = Worksheets("Sheet1")
        Set tbl = ws.ListObjects("Table1")
    
        tbl.ListRows.Add
    
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 8
    Last Post: 03-13-2023, 03:09 PM
  2. [SOLVED] Deleting/Adding rows from source data outputs "#REF" error in the consolidated table
    By Dadashvespek in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-05-2020, 03:33 AM
  3. [SOLVED] Adding Hyperlinks to the names of sheets - the formula doesn't work
    By Vitalite in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 06-23-2017, 08:20 AM
  4. [SOLVED] Adding a row below the active cell - doesn't always work first time
    By kissarmy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-17-2017, 06:48 PM
  5. Adding columns doesn;t work
    By edwardag in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 10-25-2012, 11:18 AM
  6. [SOLVED] Excel's Compress Pictures or deleting pictures doesn't seem work
    By guidod in forum Excel General
    Replies: 1
    Last Post: 01-29-2006, 02:50 AM
  7. Excel 97 - Adding Every 8th Row - Formula should work, but doesn't
    By Damaeus in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 01-23-2005, 01:06 PM

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