PC Review


Reply
Thread Tools Rate Thread

Code for Copying and Pasting data to a separate Workbook

 
 
Dave K
Guest
Posts: n/a
 
      8th Mar 2008
Hello -
I have a workbook that I copy from on a daily basis and paste into
another workbook.

In each instance, the workbook that I paste to has a slightly
different name (i.e., to account for the change in date).

As an example: I copy from Sheet5, Range A1:B20 from Workbook A, and
paste it into Sheet 3 of Workbook B, Range C120.

Is there a way to automate this via VBA? For example, is there code
that can say: select this range and place it, via paste special
values, in this workbook (perhaps where a dialog box prompts the user
for the workbook name) in this range?

Thanks in advance for any suggestions or sample code you may be able
to provide.
 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      8th Mar 2008
Hi

Place this code in the workbook that you are copying data from. I assume
that the destination workbook is opened before you run this code.

Sub CopyData()
Dim CopyTo As String

CopyTo = InputBox("Enter name of workbook to paste data to", "Regards, Per
Jessen")
Workbooks("Book1").Activate ' Change to suit
Sheets("Sheet5").Range("A1:B20").Copy

Workbooks(CopyTo).Activate
Sheets("Sheet3").Range("C120").PasteSpecial Paste:=xlPasteValues
End Sub

Regards,

Per

"Dave K" <(E-Mail Removed)> skrev i en meddelelse
news:63238dc4-61fe-4635-a371-(E-Mail Removed)...
> Hello -
> I have a workbook that I copy from on a daily basis and paste into
> another workbook.
>
> In each instance, the workbook that I paste to has a slightly
> different name (i.e., to account for the change in date).
>
> As an example: I copy from Sheet5, Range A1:B20 from Workbook A, and
> paste it into Sheet 3 of Workbook B, Range C120.
>
> Is there a way to automate this via VBA? For example, is there code
> that can say: select this range and place it, via paste special
> values, in this workbook (perhaps where a dialog box prompts the user
> for the workbook name) in this range?
>
> Thanks in advance for any suggestions or sample code you may be able
> to provide.



 
Reply With Quote
 
Don Wiss
Guest
Posts: n/a
 
      9th Mar 2008
On Sat, 8 Mar 2008 22:33:11 +0100, Per Jessen <(E-Mail Removed)> wrote:

>Place this code in the workbook that you are copying data from. I assume
>that the destination workbook is opened before you run this code.
>
>Sub CopyData()
>Dim CopyTo As String
>
>CopyTo = InputBox("Enter name of workbook to paste data to", "Regards, Per
>Jessen")
>Workbooks("Book1").Activate ' Change to suit
>Sheets("Sheet5").Range("A1:B20").Copy
>
>Workbooks(CopyTo).Activate
>Sheets("Sheet3").Range("C120").PasteSpecial Paste:=xlPasteValues
>End Sub


Activating a workbook slows down the macro. Faster is:

Sub CopyData()
Dim CopyTo As String

CopyTo = InputBox("Enter name of workbook to paste data to", "Regards, Per Jessen")
If CopyTo = "" Then Exit Sub
Application.ScreenUpdating = False
Workbooks("Book1").Sheets("Sheet5").Range("A1:B20").Copy ' Change to suit
Workbooks(CopyTo).Sheets("Sheet3").Range("C120").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False

End Sub

Don <www.donwiss.com> (e-mail link at home page bottom).
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Neat code for pasting filtered data to a separate worksheet JT Microsoft Excel Programming 10 20th Aug 2010 10:55 PM
how do i separate a document without copying & pasting into a new =?Utf-8?B?cHJpdmF0ZQ==?= Microsoft Word Document Management 6 9th Aug 2006 05:25 PM
VBA copying & pasting into a different workbook claudiaormond Microsoft Excel Programming 2 19th Jul 2006 10:52 AM
loop through a column on a workbook copying data on each row to another workbook, then copy data back to the original workbook burl_rfc Microsoft Excel Programming 1 1st Apr 2006 08:48 PM
Copying and pasting entire workbook phreud Microsoft Excel Programming 6 16th Jun 2004 10:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:54 PM.