When copying shorter table into longer, how to completely replace?

Jephph

New Member
Joined
Mar 22, 2021
Messages
14
Office Version
  1. 365
Platform
  1. MacOS
When I copy the contents of a shorter table into a longer table, the leftovers remain at the bottom.

What I'm trying to achieve:
1. I copy the contents of Table1 into Table2 (for example, 30 records each).
2. I do work on Table2 that makes it shorter by removing duplicates, say I remove 5 records so now Table2 is 25 records long.
3. I copy Table 2 back into Table1.
4. The last five records of the original Table1 remain at the bottom of the table.
5. Ultimate question: How do I make the paste function replace the whole table rather than just the top 25 records?

Code that copies but leaves a residue...
VBA Code:
ThisWorkbook.Sheets("Control Center").Range("AllData").Copy
Workbooks("US Support Schedule Form.xlsx").Sheets("Form1").Range("Table1").PasteSpecial xlPasteValues
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
before copying table2 back to table1, I will clearcontents of entire table1 then your code
VBA Code:
Workbooks("US Support Schedule Form.xlsx").Sheets("Form1").Range("Table1").ClearContents
ThisWorkbook.Sheets("Control Center").Range("AllData").Copy
Workbooks("US Support Schedule Form.xlsx").Sheets("Form1").Range("Table1").PasteSpecial xlPasteValues
 
Upvote 0
Thank you so much! It worked!

Now I have a secondary problem, the system that Table1 (the longer one) in my example above knows there used to be a row there. Now, when it appends a new row, it leaves a gap that my Copy command doesn't recognize. It only copies up to the blank line. Is there a way to include that in my copy?

Thanks again, though! Really helpful!
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,591
Members
449,089
Latest member
Motoracer88

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