+ Reply to Thread
Results 1 to 10 of 10

Copy/amalgamating Multiple Ranges

  1. #1
    Registered User
    Join Date
    06-22-2009
    Location
    Lincoln
    MS-Off Ver
    Excel 2003
    Posts
    68

    Copy/amalgamating Multiple Ranges

    I've been using this code from the ever brilliant Ron de Bruin to copy a range from multiple spreadsheets in a folder:

    Please Login or Register  to view this content.
    and it's working brilliantly.

    My problem is that I now need it to copy across multiple ranges (6 to be exact) which are different sizes. Each range needs copying to a separate sheet.

    Currently I'm achieving this by having this code in 6 separate modules and running one after the other, which does the job. The problem is the because of the coding it's opening and closing each spreadsheet 6 times.

    Could someone tell me how I'd adjust the above code to enable all 6 ranges to be copied across (including the filename) at once, so that the file only opens once.

    My coding is getting better (in fact I've altered this myself to do what I need), but I've tried and tried with this and I'm having no success.

    Thanks.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Copy/amalgamating Multiple Ranges

    Are the 6 ranges in the same sheet or in different sheets? Can you specify the ranges here, so we could get them incorporated in the code?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    06-22-2009
    Location
    Lincoln
    MS-Off Ver
    Excel 2003
    Posts
    68

    Re: Copy/amalgamating Multiple Ranges

    Arlu1201, thanks for the reply.

    The ranges I need are:

    A20:B45, M5:N20, M26:N45, W11:X28, W6:AA6, D15:E16

    And, yes, they're all on the same sheet. Each spreadsheet in the folder is identical in construction but the number if them can vary, hence why the above code works.

    Thanks for your help.
    Last edited by jennyaccord; 01-15-2012 at 04:20 AM.

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Copy/amalgamating Multiple Ranges

    You have not mentioned where these 6 ranges should be copied to. Should one range be copied to one sheet, 2nd range to the 2nd sheet, etc for each workbook?

  5. #5
    Registered User
    Join Date
    06-22-2009
    Location
    Lincoln
    MS-Off Ver
    Excel 2003
    Posts
    68

    Re: Copy/amalgamating Multiple Ranges

    Sorry Arlu.

    Each range needs copying to a separate sheet. It doesn't matter which sheets (it can simply be 1 through 6), they just have to be separate.

    The above code pulls a single range through (for all excel spreadsheets in a specified folder) and stacks them on sheet 1 with the filename in column A. I need them to stack like that, but I don't mind which sheets each range is copied to.

    Thanks for your help.

  6. #6
    Registered User
    Join Date
    06-22-2009
    Location
    Lincoln
    MS-Off Ver
    Excel 2003
    Posts
    68
    Sorry for the double post, but I thought I'd explain a bit further.

    The code above does what I needed in the beginning, and I adjusted it to serve my purposes (i.e. copying more than one range) by creating new modules and adjusting the range within each one. While this worked, running the process on the folder I had wound up taking 5mins +, as each module opened each spreadsheet in turn and only copied across the specified range.

    I thought that amalgamating the code so that all ranges were copied across from each spreadsheet at once, thereby requiring each sheet to only open once, would speed up the process. I just haven't been able to figure out how to do it.

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Copy/amalgamating Multiple Ranges

    I assume you have 6 sheets in the workbook that contains this macro
    You have to change "E:\OF\" into the foldername where the files reside.
    This code will do the whole job:

    Please Login or Register  to view this content.
    Last edited by snb; 01-17-2012 at 11:24 AM.



  8. #8
    Registered User
    Join Date
    06-22-2009
    Location
    Lincoln
    MS-Off Ver
    Excel 2003
    Posts
    68

    Re: Copy/amalgamating Multiple Ranges

    Thanks for the reply snb.

    I've added the code and when I run it I'm getting a syntax error on the getobject(c01) line.

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Copy/amalgamating Multiple Ranges

    You are a keen observer

    Use
    Please Login or Register  to view this content.
    Last edited by snb; 01-17-2012 at 11:26 AM.

  10. #10
    Registered User
    Join Date
    10-11-2013
    Location
    falkirk
    MS-Off Ver
    Excel 2007
    Posts
    69

    Re: Copy/amalgamating Multiple Ranges

    .................. ...........................
    Last edited by ids; 12-03-2013 at 08:32 AM.

+ 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