Copy data from one table to another - hidden columns

Steven101

Board Regular
Joined
Oct 27, 2014
Messages
62
Hi I have 2 sheets;

Sheet1 has Table1
Sheet2 has Table2

Both tables have identical headings, however both have multiple columns (same) hidden to make ease of viewing

I'm looking to create a macro that will copy the table contents of table1 into the last completed row +1 of Table2. Essentially adding to Table2.

Any help would be appreciated.

Thank
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try this:
Code:
Public Sub Copy_Table1_To_Table2()
    
    Dim table1 As ListObject
    Dim table2 As ListObject
    Dim table2numDataRows As Long
    
    Set table1 = ActiveWorkbook.Worksheets("Sheet1").ListObjects("Table1")
    Set table2 = ActiveWorkbook.Worksheets("Sheet2").ListObjects("Table2")
    
    With table2
        table2numDataRows = .DataBodyRange.Rows.Count
        .Resize .Range.Resize(.Range.Rows.Count + table1.DataBodyRange.Rows.Count)
        table1.DataBodyRange.Copy .DataBodyRange.Offset(table2numDataRows, 0)
    End With
    
End Sub
 
Upvote 0
Thanks John_w, works a treat, with one problem.

The data copied over includes formula, is there a way of pasting the data in as values?

Thanks, S
 
Upvote 0
This macro copies Table1 values:

Code:
Public Sub Copy_Table1_Values_To_Table2()
    
    Dim table1 As ListObject
    Dim table2 As ListObject
    
    Set table1 = ActiveWorkbook.Worksheets("Sheet1").ListObjects("Table1")
    Set table2 = ActiveWorkbook.Worksheets("Sheet2").ListObjects("Table2")
    
    With table2
        .DataBodyRange.Resize(table1.DataBodyRange.Rows.Count).Offset(.DataBodyRange.Rows.Count, 0).Value = table1.DataBodyRange.Value
    End With
    
End Sub
The original code can be simplified:
Code:
Public Sub Copy_Table1_To_Table2()
    
    Dim table1 As ListObject
    Dim table2 As ListObject
    
    Set table1 = ActiveWorkbook.Worksheets("Sheet1").ListObjects("Table1")
    Set table2 = ActiveWorkbook.Worksheets("Sheet2").ListObjects("Table2")
    
    With table2
        table1.DataBodyRange.Copy .DataBodyRange.Resize(table1.DataBodyRange.Rows.Count).Offset(.DataBodyRange.Rows.Count, 0)
    End With
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,970
Members
448,933
Latest member
Bluedbw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top