Closing workbook after pasting

Chewyhairball

Active Member
Joined
Nov 30, 2017
Messages
303
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
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
59,875
Office Version
  1. 365
Platform
  1. Windows
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

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.

Forum statistics

Threads
1,195,948
Messages
6,012,472
Members
441,701
Latest member
vnkendijs

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
Top