Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

vba

ResolvedVersion 2003

Christopher has attended:
Excel Advanced course
Excel VBA Intro Intermediate course

VBA

How can I copy a range from one sheet then paste the data to another sheet on a different drive

Copy Data to Workbook on another drive

Hi Christopher

The code below allows you to copy data from one workbook and paste it in a workbook on another drive.

Note you open the target workbook, paste the data and then close it saving the new data.

Sub CopyData

Dim WSheet As String

WSheet = "D:/NewWorkbook.xls" 'The path of the target workbook

Range("A1:G1").Copy
Workbooks.Open Filename:=WSheet 'Opens the workbook in the other drive
Sheets("Sheet1").Select
Range("A1").Select
ActiveSheet.Paste
ActiveWorkbook.Close SaveChanges:=True 'Closes the target workbook and saves changes

End Sub

Hope this helps

Carlos

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Switching Between Spreadsheets

As the Alt+Tab key switches between loaded applications or files, Ctrl+Tab switches between loaded or open Excel files. Hold down the Ctrl key until you have tabbed to the correct spreadsheet.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.