Copy and paste with code from open workbook to closed workbook.

asyamonique

Well-known Member
Joined
Jan 29, 2008
Messages
1,286
Office Version
  1. 2013
Platform
  1. Windows
Code:
Dim LR As Long
Range("AL2:AO53").Copy
Workbooks.Open Filename:="S:\Entries\Entries.xls"
LR = Range("A" & Rows.Count).End(xlUp).Row
ActiveSheet.Range("A" & LR + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWorkbook.Save
ActiveWindow.Close

Good Day,
Im having trouble with the above code.
Its simply copying the datas from master file and paste into the closed workbook.
Could anybody help me on that why its not copying from A1 and all the way down.
The datas goes different ranges and when i make the next click its overwriting the new datas on same location.
Many Thanks
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
What closed workbook?

You seem to be opening the workbook you are pasting in and copying from the workbook the code is in, which I assume is open.

Mind you opening the workbook might be clearing the clipboard.
Code:
Dim wb As Workbook
Dim rngSrc As Range
Dim rngDst As Range
Dim LR As Long

     Set rngSrc = Range("AL2:AO53")

     Set wb = Workbooks.Open (Filename:="S:\Entries\Entries.xls")
 
     Set rngDst = wb.ActiveSheet.Range("A" & Rows.Count).End(xlUp).Offset(1)
 
     rngSrc.Copy

     rngDst.PasteSpecial Paste:=xlPasteValues

    wb.Save

    wb.Close False
 
Upvote 0
What closed workbook?

You seem to be opening the workbook you are pasting in and copying from the workbook the code is in, which I assume is open.

Mind you opening the workbook might be clearing the clipboard.
Code:
Dim wb As Workbook
Dim rngSrc As Range
Dim rngDst As Range
Dim LR As Long
 
     Set rngSrc = Range("AL2:AO53")
 
     Set wb = Workbooks.Open (Filename:="S:\Entries\Entries.xls")
 
     Set rngDst = wb.ActiveSheet.Range("A" & Rows.Count).End(xlUp).Offset(1)
 
     rngSrc.Copy
 
     rngDst.PasteSpecial Paste:=xlPasteValues
 
    wb.Save
 
    wb.Close False

Thanks for the quick reply.
Norie, what if the destination workbook has password,
Many thanks.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,134
Members
452,890
Latest member
Nikhil Ramesh

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