+ Reply to Thread
Results 1 to 9 of 9

Excel VBA copying data from closed workbooks with multiple different pathways

  1. #1
    Registered User
    Join Date
    07-08-2017
    Location
    Minnesota
    MS-Off Ver
    Microsoft Office 2016
    Posts
    74

    Excel VBA copying data from closed workbooks with multiple different pathways

    Hello,

    The below code works for summing column C in the closed workbooks and dividing by 2 and pasting the data into the current workbook with the macro. I am needing to manipulate the formula so it can go into multiple pathways instead of all workbooks being located under the same pathway. Is there a way I can have the folder pathway reference a column (a cell for each pathway, i.e., G1, G2, G3, G4) in the worksheet, so then I can just change the pathway if needed in Excel and then the Macro will reference that for pulling the data?

    This code assumes all workbooks are in same folder.
    Please Login or Register  to view this content.
    I tried below, but I get an error.
    Please Login or Register  to view this content.
    Last edited by Hoover5896; 07-10-2017 at 03:30 PM.

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,176

    Re: Excel VBA copying data from closed workbooks with multiple different pathways

    Has each path got the same workbooks that are stored in the array...
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Registered User
    Join Date
    07-08-2017
    Location
    Minnesota
    MS-Off Ver
    Microsoft Office 2016
    Posts
    74

    Re: Excel VBA copying data from closed workbooks with multiple different pathways

    No each pathway only has one workbook. So I am guessing I need to setup some other variable instead of an array to go into each folder and pull the workbook data, but I am not sure how to do that?

    End result, I am trying to create something that can go into up to 75 different folder pathways and pull different workbook names, i.e., Cudahy Center 06.17.xlsx", "Wellington Park 06.17.xlsx", "Wausau 06.17.xlsx", "Forest Plaza 06.17.xlsx all that have "Trial Balance" as the sheet name and sum column C and divide by 2, then insert that number into column A1, A2, A3, etc. of current workbook with macro.

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Excel VBA copying data from closed workbooks with multiple different pathways

    It all sounds a bit messy -apologies if I have misunderstood what you want.
    I bet you spend hours drilling down through that folder structure
    I assume each file name exists only once and therefore exists in only one path
    As I am away from my PC, I cannot test any code for a few days but here are some thoughts

    On sheet 1 :
    create a lookup table of the relevant files and related pathways (Table 1)
    - use an Excel "Table" to allow files to be added easily and then sorted
    - column1 = file name
    - column2 = path

    On sheet 2:
    The area to select specific files to be consolidated - use another Excel Table (Table 2)
    - column 1 select file from dropdown
    - column 2 = lookup formula (provides the path from other table)

    Now you can refer in your code to Table 2 and that has everything you need

    Amend the file names in Table 2 and run your VBA again
    Could even have more than one VBA routine using the same "selection area"
    Table 1 could be also placed in its own file and be looked up in any code from any file

    .... or am I missing something fundamental?
    Last edited by kev_; 07-11-2017 at 06:12 PM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Excel VBA copying data from closed workbooks with multiple different pathways

    Quote Originally Posted by Hoover5896 View Post
    Hello,
    Is there a way I can have the folder pathway reference a column (a cell for each pathway, i.e., G1, G2, G3, G4) in the worksheet, so then I can just change the pathway
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-08-2017
    Location
    Minnesota
    MS-Off Ver
    Microsoft Office 2016
    Posts
    74

    Re: Excel VBA copying data from closed workbooks with multiple different pathways

    That worked perfectly! Making it even better, can I make it so the workbook names can be referenced in column F too, so I do not need to go into VBA and type each workbook name anytime there is an update and can just do so in column F?

    Please Login or Register  to view this content.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Excel VBA copying data from closed workbooks with multiple different pathways

    Do you mean
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    07-08-2017
    Location
    Minnesota
    MS-Off Ver
    Microsoft Office 2016
    Posts
    74

    Re: Excel VBA copying data from closed workbooks with multiple different pathways

    It looks like I get a "Compile Error - Expected Array" with this. I am trying to do the same as what we did in G2, G3, G4, etc for following the folder pathway, but having the folder pathway typed in Excel and not the VBA so it is easier to update, but instead doing it in F2, F3, F4, etc. to know the workbook name it needs to go into instead of listing all the workbook names out in VBA.

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Excel VBA copying data from closed workbooks with multiple different pathways

    Ah,
    Please Login or Register  to view this content.
    It should be the number that you have value in col.F.
    Perhaps
    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)

Similar Threads

  1. Copying specific cells from different closed workbooks to a Master Excel file
    By kennad in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-11-2015, 09:34 AM
  2. Copying data from a master worksheet to a folder full of closed workbooks
    By Simsam_g in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-15-2015, 04:20 AM
  3. Copying specific data ranges from multiple (closed or in use by others) workbooks
    By TheRetroChief in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-19-2014, 10:39 AM
  4. Copying rows from multiple closed workbooks to active workbook
    By onbeillp111 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-24-2013, 11:19 AM
  5. [SOLVED] Copying cells from multiple closed workbooks to active workbook
    By Anonym216 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-16-2013, 07:53 AM
  6. VBA: Copying data from closed workbooks
    By staffordalex in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2008, 01:20 PM
  7. Copying data from closed Workbooks
    By danman1043 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-03-2008, 09:11 AM

Tags for this Thread

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