+ Reply to Thread
Results 1 to 3 of 3

Problem Copying Table Column to Another Table

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-08-2012
    Location
    San Clemente, California
    MS-Off Ver
    Office365
    Posts
    383

    Problem Copying Table Column to Another Table

    I am trying to copy the first column of one table to the first column of another table.

    The code first deletes all the data in the receiving table while preserving formulas. But when the new data is pasted the results extend beneath the table's total row. The table is not expanded to receive the new data.

    Here is the code.

    Sub CopyTableColumn()
        
        Dim loSource As Object
        Dim loTarget As Object
    
        Set loSource = Sheets("Sheet1").ListObjects("tblSource")
        Set loTarget = Sheets("Sheet1").ListObjects("tblTarget")
       
        On Error GoTo Continue                  'bypasses error if table is already empty
        Application.DisplayAlerts = False
        loTarget.DataBodyRange.Rows.Delete      'Deletes all data, leaves 1 row with formulas intact.
        Application.DisplayAlerts = True
    Continue:
    
        loSource.ListColumns(1).DataBodyRange.SpecialCells(xlCellTypeVisible).Copy Destination:=Range("tblTarget[[column1]]")
        
        Application.CutCopyMode = False
    End Sub
    Any help would be most appreciated.

    Thanks!

  2. #2
    Forum Contributor
    Join Date
    10-08-2012
    Location
    San Clemente, California
    MS-Off Ver
    Office365
    Posts
    383

    Re: Problem Copying Table Column to Another Table

    ...Upon further checking, I might need to Resize the table before pasting but I could use some help with that syntax.

    Thanks, again for checking on this.

  3. #3
    Forum Contributor
    Join Date
    10-08-2012
    Location
    San Clemente, California
    MS-Off Ver
    Office365
    Posts
    383

    Re: Problem Copying Table Column to Another Table

    ...SOLVED...I think. I just learned that when copying data into an existing table that the totals row must be turned off.

    loTarget.ShowTotals = False
    With that addition, the code above works. After new data is added we can turn totals back on with

    loTarget.ShowTotals = True
    Many thanks to all who were looking in on this problem.

    tom

+ 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. Replies: 6
    Last Post: 01-24-2017, 06:56 PM
  2. Copying Excel table range to an existing PPT slide, pasting as TABLE, not as PICTURE
    By gurnblanston27 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-22-2016, 04:44 PM
  3. Copying and pasting a table with formulas within the same worksheet problem
    By feelinglikeanoob in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 09-19-2016, 01:48 AM
  4. [SOLVED] Copying a Formula Down a Column in an Existing Table
    By MausDef in forum Excel General
    Replies: 6
    Last Post: 11-19-2015, 04:19 PM
  5. Replies: 2
    Last Post: 08-27-2014, 03:13 PM
  6. [SOLVED] Formula for copying over relevant data from one table to populate another table
    By amasson in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 02-25-2013, 12:41 PM
  7. Replies: 1
    Last Post: 02-03-2013, 09:05 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