Closing workbook after pasting

Chewyhairball

Active Member
Joined
Nov 30, 2017
Messages
312
Office Version
  1. 365
Platform
  1. Windows
Hi

I am copying data from workbook 2(name changes) to workbook1(fixed name).
My code is stored in workbook1 and run from workbook 2 window. It has to be this way as workbook 2 is not mine and is locked.

Once the data has been copied from workbook2 it is pasted into workbook1.
VBA Code:
Application.ScreenUpdating = False
  Sheets("Sheet1").Select
    Range("A1").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range("A1:DZ321").Select
    Selection.Copy

     Windows("Workbook1"). _
        Activate
       
    Sheets("Sheet1").Select
  
    Range("A3").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False

What I would like to do is shutdown workbook2( or whatever it is called) without saving it.
I have tried doing it using
VBA Code:
ActiveWorkbook.Close savechanges:=False
before activating worksheet1 which works to an extent and does close workbook2.
However it comes up with a message about large amounts of data on the clipboard and doesnt paste the data into worksheet 1.

any help is appreciated

thank Rory
 
I see what you are saying Alex but I think there may be too many unknowns to be trying to cope with variations like you are suggesting as we don't know what the OP would actually want if rows were inserted in the source worksheet, or if that is even possible with their worksheet. It might be that A1 is to be the 'absolute' starting position no matter what.

Further, since CurrentRegion has been accepted as part of the solution, that may (or may not) still start from A1 even if rows have been inserted.

In any case, the main thing is that the OP has a result that they seem happy about. :)
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,214,944
Messages
6,122,384
Members
449,080
Latest member
Armadillos

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