+ Reply to Thread
Results 1 to 9 of 9

VBA Code to copy cell range from multiple workbooks?

  1. #1
    Forum Contributor
    Join Date
    05-12-2014
    MS-Off Ver
    Excel 2013
    Posts
    131

    VBA Code to copy cell range from multiple workbooks?

    Hey folks!
    I could use a nudge in the right direction here. I have a large document at work that houses a range of values for numerous users, and then separate documents for each user that they fill in themselves. Every week, I have to open the user doc, copy a range of cells, paste into their respective range, and repeat that process for ALL users. It's time consuming and frustrating since I'm sure there's a more automatic way to set this up.

    I found some VBA code that'd allow me to copy a range from an open workbook, but I'd like to skip the open workbook part since it sort of defeats the purpose. Additionally, the VBA code I found only allows for one range on one workbook to be copied, where I'd actually need to copy a range from multiple workbooks. So for example:

    The main document is saved out by week. The user documents are saved out by month. I'd like to have some code on the main workbook via a macro I can set up to go look at User1's workbook (closed, though), and copy cells A2:F23 and then paste them into cells A1:F22 on the main document. Then, before completing, it would go to User2's workbook, and do the same thing, only paste into cells A21:F42. Then User 3, User 4, etc. etc.

    Is there ANY way to do this?

    I've attached an example worksheet. Tab 1 is how the individual user documents are set up, and tab 2 is how the main document is set up (you'll notice on tab 2 there are different users, but each week range is the same).

    Any help would be greatly appreciated, and if you need more info, just ask! Thanks!
    Attached Files Attached Files
    Last edited by mrbusto71; 01-28-2016 at 02:41 PM. Reason: Title change

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,615

    Re: Help me VBA Kenobi, you're my only hope

    title updated
    Last edited by protonLeah; 01-28-2016 at 08:08 PM.
    Ben Van Johnson

  3. #3
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA Code to copy cell range from multiple workbooks?

    Are the user files all in the same directory?
    Is the Directory the same for the user files as for the main document file? If not, what is the directory for the user files?
    Do they have a common string in their file name so they can be isolated from other Excel files in that directory?
    The ranges in the OP narrative does not coincide with the examples in the attachment, which, if either, is correct?

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,477

    Re: VBA Code to copy cell range from multiple workbooks?

    What's your issue with opening and closing multiple workbooks? Personally, I think it's a much simpler process than messing about with code to process data in closed workbooks. And, if I'm honest, I don't think there's that much of a speed difference.

    Your description doesn't match the data in the sample and your description would have you overwriting data.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Forum Contributor
    Join Date
    05-12-2014
    MS-Off Ver
    Excel 2013
    Posts
    131

    Re: VBA Code to copy cell range from multiple workbooks?

    Quote Originally Posted by JLGWhiz View Post
    Are the user files all in the same directory?
    Is the Directory the same for the user files as for the main document file? If not, what is the directory for the user files?
    Do they have a common string in their file name so they can be isolated from other Excel files in that directory?
    The ranges in the OP narrative does not coincide with the examples in the attachment, which, if either, is correct?
    Heya! In order(anything in CAPS would be replaced by whatever the CAPS stuff says):
    1.) Sort of. Each user is saved in their respective supervisor's folder. So it'd be like: C:\Documents\SUPERVISORNAME\USERNAME.xlsx The C\Docs part is the same for everyone though.
    2.) Nope! Main Doc file would look something like this: C:\Documents\Reports\MONTH\WEEK.xlsx
    3.) Each document is named either for the worker or the week, so they're all different. (Not sure if that addresses your question)
    4.) The ranges provided in the original were just made up. The ranges that would need copying are cells A2:I15 on the first tab, and that would go into the same cell range on the 2nd tab. However for a 2nd user, while the first source would remain the same (i.e. copying JANE DOE's sheet, cells A2:I15 still), the paste location for the 2nd tab would be different since I'm wanting it to paste her information to her relevant area. So in this made up scenario, JANE DOE's information would be pasted to A18:I30 on the 2nd tab.

    Hopefully all of that made sense!
    Last edited by mrbusto71; 01-28-2016 at 02:58 PM.

  6. #6
    Forum Contributor
    Join Date
    05-12-2014
    MS-Off Ver
    Excel 2013
    Posts
    131

    Re: VBA Code to copy cell range from multiple workbooks?

    Quote Originally Posted by TMS View Post
    What's your issue with opening and closing multiple workbooks? Personally, I think it's a much simpler process than messing about with code to process data in closed workbooks. And, if I'm honest, I don't think there's that much of a speed difference.

    Your description doesn't match the data in the sample and your description would have you overwriting data.

    Regards, TMS
    There's nothing inherently wrong with opening each workbook, it's just that it has to be done for upwards of 100 users. So each week it's just a mind numbing task of opening the main document, then going to user1, open, copy, paste, close. User2, open, copy, paste, close. Repeat ad nauseum until finished.

    While figuring out code would require some effort, it'd also allow for multi-tasking whereas the current process does not. If I had a macro, I could open the main document, run the macro, then just minimize Excel in the background while it did its thing and work on other things until it was done.

    As to the data portion, I updated the info in my previous reply. Hopefully everything makes sense

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,477

    Re: VBA Code to copy cell range from multiple workbooks?

    You misunderstand me. If you use a macro to cycle through the workbooks, you've removed the drudgery regardless of whether you (the code) opens the files or not.

    Regards, TMS

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA Code to copy cell range from multiple workbooks?

    Are all the user files in the same folder ? Same directory?

  9. #9
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA Code to copy cell range from multiple workbooks?

    Quote Originally Posted by JOHN H. DAVIS View Post
    Are all the user files in the same folder ? Same directory?
    @JOHN H. DAVIS, see post #5, which responds to post # 3. Looks like files would need to be listed on separate sheet and work from there. I don't want to tackle this one, I'm out of here.

+ 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. Hi hope you can help.
    By fktripodi in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 12-15-2015, 05:16 PM
  2. Hi everyone, hope everyone is doing well....
    By sshrikanth2 in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 01-25-2013, 02:03 PM
  3. hope someone can help!
    By cyncarrier in forum Excel General
    Replies: 1
    Last Post: 06-27-2009, 05:05 PM
  4. Hope someone can help me
    By Jay Blatherwick in forum Excel General
    Replies: 1
    Last Post: 06-15-2006, 01:10 PM
  5. Hope someone here can help me
    By AlienBeans in forum Excel General
    Replies: 9
    Last Post: 03-16-2006, 08:37 PM
  6. Hope Someone Can Help...
    By Farah in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-04-2005, 08:05 AM

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