+ Reply to Thread
Results 1 to 2 of 2

Macro to resize table by however many new entries are made

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-20-2011
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007, Excel 2003, Excel 2010
    Posts
    284

    Macro to resize table by however many new entries are made

    Hello:

    The code below adds data from a range in sheet 1 to a table in sheet 2. How could I edit the following line so that the table will resize by the number of new entries that are pasted.

    ActiveSheet.ListObjects("Table1").Resize Range("$A$1:$B$10")



    Sub CopyPaste()
        
        Dim i As Long   'i is the last row in column B of sheet2
        Dim j As Long   'j is the last row + 1 in column A of sheet1
        
        i = Sheets("sheet1").Cells(Rows.Count, 2).End(xlUp).Row
        j = Sheets("sheet2").Cells(Rows.Count, 1).End(xlUp).Row + 1
        
        Sheets("sheet1").Range("A2:J" & i).Copy Sheets("sheet2").Range("A" & j)
        
        Sheets("Sheet2").Select
        ActiveSheet.ListObjects("Table1").Resize Range("$A$1:$B$10")
    End Sub

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Macro to resize table by however many new entries are made

    hi rlsublime
    Have you tried..

    ActiveSheet.ListObjects("Table1").Resize Range("A1:B" & J+i)
    is this for a chart?
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

+ 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