+ Reply to Thread
Results 1 to 4 of 4

Copy range of cells of one workbook, to another workbook.

  1. #1
    Registered User
    Join Date
    12-06-2012
    Location
    Belgium
    MS-Off Ver
    Excel 2007
    Posts
    2

    Copy range of cells of one workbook, to another workbook.

    Hi,
    I am trying to copy a range of cells from one sheet of Workbook A to another closed excel workbook B using a macro. The two workbooks are in a different folder.
    I have three macros in total that all work fine independently. But once combined it doesn't copy the cells to workbook B
    1) Macro1: A recorded macro that copies cell from workbook A and pastes them in Workbook B.
    2) Macro2: Simply opens up workbook B
    3) Combines the 2 macros from above and is attached to a button in workbookA.

    The codes:
    Macro1:
    Please Login or Register  to view this content.
    Macro2:

    Please Login or Register  to view this content.
    Macro3:
    Please Login or Register  to view this content.
    I have no experience in VB, so any help is much appreciated!

    Thank you!

  2. #2
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Copy range of cells of one workbook, to another workbook.

    Hi
    I'm guessing your problem is that, when you run the second macro opening workbook B, this will become the active window. So running the second macro at that point will copy from workbook B not workbook A.

    try putting all the steps in one macro, something like this (you will need to adjust the ranges and sheet names or numbers):

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-06-2012
    Location
    Belgium
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Copy range of cells of one workbook, to another workbook.

    Hi NickyC,

    Thank you very much for your input!

    I have tried your code, but it doesn't work. It gives error 438 on the third line of the code.
    Please Login or Register  to view this content.
    Also, can you give me some explanation about the second line, where you assign words as strings. I am new to this and have no experience, so it would be very useful to get me started on this
    Is the "NewDir" line used? meaning, does it know that workbookB is in that folder?
    And is the code that I highlighted in red, correct?

    I am waiting anxiously to your reply!

    Thank you again!

    hulstronics

  4. #4
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Copy range of cells of one workbook, to another workbook.

    NewDir is the directory of the destination file. it needs a concluding "\" to work
    NewFile is the name of the destination file
    ThisFile should be the name of the source file. I expect "ActiveWorkbook.workbookA" will return nothing
    if Blad1 is the name of a sheet, it should be in quotation marks

    basically, if you are referring to something by its name, you need to wrap it in quotation marks. if you are referring to data stored in a variable, you refer to that variable without quotation marks.

    so

    Please Login or Register  to view this content.
    or

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.6.0 RC 1