Results 1 to 4 of 4

Thread: [RESOLVED] Copy & Paste between Workbooks

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Location
    Best Place on Earth
    Posts
    363

    Resolved [RESOLVED] Copy & Paste between Workbooks

    I have a Master spreadsheet which loads up data from various sources and
    saves itself under a new name with the current date, i.e. Master20060712.xls

    The user can then work on the spreadsheet with the new name and add
    comments, etc in certain columns.

    I have been trying to copy some columns of data from the new spreadsheet
    to the original, I started out by using the Record Macro and got the following
    code.

    VB Code:
    1. Workbooks.Open Filename:= ThisWorkbook.Path & "\" & MasterWBK
    2.     Windows("Master20060712").Activate
    3.     Columns("I:Q").Select
    4.     Selection.Copy
    5.     Windows("Master.xls").Activate
    6.     Range("I1").Select
    7.     ActiveSheet.Paste

    I adapted it as follows :-

    VB Code:
    1. ' Declared Elsewhere
    2. Const MasterWBK = "Master.xls"
    3.  
    4. ' Placed in the Workbook_BeforeClose Sub
    5.     If ThisWorkbook.Name <> MasterWBK Then ' Dont do this if I am working in the Original File
    6.         Workbooks.Open Filename:= ThisWorkbook.Path & "\" & MasterWBK
    7.         ThisWorkbook.Activate
    8.         Columns("I:Q").Select
    9.         Selection.Copy
    10.         Workbooks(MasterWBK).Activate
    11.         Range("I1").Select
    12.         ActiveSheet.Paste
    13.         Workbooks(MasterWBK).Close SaveChanges:=True
    14.     End If

    For some reason when I run this, although it seems to work it does save
    the pasted data.

    Can anyone offer any advice as to why this is not working properly.

    I have since changed to using the following simplistic code , but would like to know why the above did not work.

    VB Code:
    1. Row = 1
    2. Do
    3.     Col = 9
    4.     Do
    5.       Workbooks(MasterWBK).ActiveSheet.Cells(Row,Col).Value = ThisWorkbook.ActiveSheet.Cells(Row,Col).Value
    6.       Col = Col + 1
    7.       If ExitConditions Then
    8.          Exit Do
    9.      End If
    10.     Loop
    11.     Row = Row + 1
    12.     If  ExitCondition Then
    13.         Exit Do
    14.     End If
    15. Loop
    Last edited by Torc; Jul 14th, 2006 at 03:14 AM.
    Signature Under Construction

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Copy & Paste between Workbooks

    change:
    VB Code:
    1. Range("I1").Select
    2. ActiveSheet.Paste

    to
    VB Code:
    1. Range("I1").PasteSpecial
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Location
    Best Place on Earth
    Posts
    363

    Re: Copy & Paste between Workbooks

    Thanks.

    So simple.
    Signature Under Construction

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Copy & Paste between Workbooks

    No Problem...

    could you possibly mark the thread resolved? (Just click thread tools > Mark thread resolved)

    thanks!!
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

Posting Permissions

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



Click Here to Expand Forum to Full Width