+ Reply to Thread
Results 1 to 9 of 9

Copying Multiple Ranges to another workbook not working

  1. #1
    Registered User
    Join Date
    12-08-2013
    Location
    United States
    MS-Off Ver
    Microsoft 365
    Posts
    57

    Copying Multiple Ranges to another workbook not working

    Hi All!
    I created a VBA macro to copy data from specific worksheets in a workbook to another workbook with the same worksheet names. The code is looping through the worksheet correctly, but the code I have to copy specific ranges from the source workbook and then paste it to the target workbook is not working. The code will copy a single cell over in the loop, but not a range of cells. Below is my code.

    I thank you in advance for your assistance.

    - Ron -

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Copying Multiple Ranges to another workbook not working

    When you open the Source workbook, it becomes the active workbook. You then set your target to the active workbook. So then the source and target are the same workbook.

    Solution: set the target to the active workbook before opening the source workbook.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Copying Multiple Ranges to another workbook not working

    Quote Originally Posted by AlphaFrog View Post
    When you open the Source workbook, it becomes the active workbook. You then set your target to the active workbook. So then the source and target are the same workbook.
    Like Alphadog said you just have to swap these lines

    Please Login or Register  to view this content.
    Thanks

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Copying Multiple Ranges to another workbook not working

    You have to swap these lines

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    12-08-2013
    Location
    United States
    MS-Off Ver
    Microsoft 365
    Posts
    57

    Re: Copying Multiple Ranges to another workbook not working

    Hi AlphaFrog!
    First, I want to thank you for taking the time to look at my code.

    I switched the lines to set the target to the active workbook before opening the source workbook. See the code below. But it is still not copying over the data from the source workbook to the target workbook. Thanks again for your help.

    Please Login or Register  to view this content.
    - Ron -

  6. #6
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Copying Multiple Ranges to another workbook not working

    try adding ".value" at the end of each range

    so this line:
    Please Login or Register  to view this content.
    becomes:
    Please Login or Register  to view this content.
    Thanks

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Copying Multiple Ranges to another workbook not working

    Is Finance13new.xlsm the active workbook when you start the macro?

  8. #8
    Registered User
    Join Date
    12-08-2013
    Location
    United States
    MS-Off Ver
    Microsoft 365
    Posts
    57

    Re: Copying Multiple Ranges to another workbook not working

    Hi Fredlo2010!
    It worked!

    Thank you so much for your and AlphaFrog assistance. It is very much appreciated.

    - Ron -

  9. #9
    Registered User
    Join Date
    12-08-2013
    Location
    United States
    MS-Off Ver
    Microsoft 365
    Posts
    57

    Re: Copying Multiple Ranges to another workbook not working

    Hi AlphaFrog!
    I added .value at the end as fredlo2010 suggested and it worked.

    Thank you for your help, which started the ball rolling with fixing my code. I very much appreciated your help in this matter.

    - Ron -

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copying data from one workbook to another using name ranges.
    By Turtleman10 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-03-2013, 09:35 AM
  2. Copying and pasting Named (Dynamic) Ranges from one workbook to the other
    By Let in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-23-2012, 10:06 AM
  3. [SOLVED] Copying ranges of cells from different worksheets in a workbook based on an if then
    By stinkybottom in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 06-13-2012, 09:19 PM
  4. Replies: 2
    Last Post: 10-14-2007, 01:05 PM
  5. [SOLVED] named ranges and copying sheets to another workbook
    By helpwithXL in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-17-2005, 12:06 PM

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