+ Reply to Thread
Results 1 to 3 of 3

Thread: Copy paste between workbooks.

  1. #1
    Registered User
    Join Date
    11-05-2004
    Posts
    3

    Question Copy paste between workbooks.

    I need someto gove me a good idea ofthe best way to do a copy paste between workbooks. I have been doine it as follows:

    Sub FACSub1()
    '
    ' FACSub1 Macro
    ' Macro recorded 7/22/2011 by lvannorman
    '
    '
    ActiveSheet.Range("N2:Y2").Select
    Selection.Copy
    ChDir "\\SERVER\Shared\Operation Production\z Reports"
    Workbooks.Open Filename:= _
    "\\SERVER\Shared\Operation Production\z Reports\FAC Sub-Assembly Batch Summary.xls"
    Sheets("Summary information").Select
    Range("A2").Select
    While Not IsEmpty(ActiveCell)
    ActiveCell.Offset(1, 0).Select
    Wend
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    ActiveWorkbook.Save
    ActiveWorkbook.Close
    End Sub


    But I have been told that I should place the selection copy command after the "wend" and not at the beginning.

    All suggestions + comments welcome.

    Thanks

  2. #2
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    359

    Re: Copy paste between workbooks.

    Please read the forum rules regarding code tags - all code you post must be enclosed in code tags - see the rules here.
    You need to loop through the range and paste the values into the next blank cells
    Sub FACSub1()
    ActiveSheet.Range("N2:Y2").Copy
    ChDir "\\SERVER\Shared\Operation Production\z Reports"
    Workbooks.Open Filename:= _
    "\\SERVER\Shared\Operation Production\z Reports\FAC Sub-Assembly Batch Summary.xls"
    Sheets("Summary information").Range("A2").Select
    While Not IsEmpty(ActiveCell)
    ActiveCell.Offset(1, 0).Select
    Wend
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    ActiveWorkbook.Close True ' this will save and close the workbook in one statement
    End Sub
    Hope this helps.
    Anthony
    “Confidence never comes from having all the answers; it comes from being open to all the questions.”
    PS: Remember to mark your questions as Solved once you are satisfied and rate the answer(s) questions.”
    Last edited by smuzoen; 02-03-2012 at 05:31 PM. Reason: Fix code

  3. #3
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    359

    Re: Copy paste between workbooks.

    But I have been told that I should place the selection copy command after the "wend" and not at the beginning.
    The wend is the end of the loop in the previous post and the paste command needs to be here as you loop through cells until you find the next cell that is empty.
    See edited code - misunderstood - sorry. If you want to paste the values into the last free row in Column A then you could use
    Sub FACSub1()
    ActiveSheet.Range("N2:Y2").Copy
    ChDir "\\SERVER\Shared\Operation Production\z Reports"
    Workbooks.Open Filename:= _
    "\\SERVER\Shared\Operation Production\z Reports\FAC Sub-Assembly Batch Summary.xls"
    Sheets("Summary information").Range("A" & Cells(Rows.Count, "A").End(xlUp).Row + 1).PasteSpecial _
    Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    ActiveWorkbook.Close True
    End Sub
    Hope this helps.
    Anthony
    “Confidence never comes from having all the answers; it comes from being open to all the questions.”
    PS: Remember to mark your questions as Solved once you are satisfied and rate the answer(s) questions.”
    Last edited by smuzoen; 02-03-2012 at 05:45 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0