I need to copy and paste values to another workbook

Eric Penfold

Active Member
Joined
Nov 19, 2021
Messages
424
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I need to only copy newly pasted values to another workbook. How could I adjust this code to make that work.

VBA Code:
Private Sub CopyData()

    Dim SourceWb As Workbook, DestWb As Workbook
    Dim SourceWs As Worksheet, DestWs As Worksheet
    Dim IfDataExist As Boolean
    Dim tbl    As ListObject
    Dim Rng    As Variant, FileToOpen As Variant
    Dim LRow   As Long, Row As Long

    With Application
        .EnableEvents = False
        .ScreenUpdating = False
        .DisplayAlerts = False
        .Calculation = xlCalculationManual
    End With
   
    Set SourceWb = Workbooks("2023BackOrderReport.xlsm")
    Set SourceWs = SourceWb.Worksheets("Data")
        LRow = SourceWs.Cells(Rows.Count, 1).End(xlUp).Row
    Set Rng = SourceWs.Range("A2:A" & LRow)
   
    FileToOpen = ("S:\SALES\ADMIN\Intact Import\DR - Sales Order BO Report.xlsx")
    Workbooks.Open FileToOpen
   
    Set DestWb = Workbooks("DR - Sales Order BO Report.xlsx")
    Set DestWs = DestWb.Worksheets("BOReported")
       
        Set Rng = DestWs.Range("A2:A" & LRow)
       
DestWs.Range("A2").CurrentRegion.Delete

       
        SourceWs.Range("A2:A" & LRow).Copy
        DestWs.Range("A2:A" & LRow).Select
        Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
       
End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I need to only copy newly pasted values to another workbook. How could I adjust this code to make that work.
How exactly do you identify the "newly pasted values"? Is there a datestamp somewhere on each row?

I think it would be helpful if you showed us a sample of each file, and explain exactly how to determine which rows need copying over.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0

Forum statistics

Threads
1,215,079
Messages
6,123,000
Members
449,092
Latest member
masterms

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