+ Reply to Thread
Results 1 to 41 of 41

Need a Macro to Create a Dynamic Index/Match among Cumulated Files

  1. #1
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Question Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    I have a template that updates periodically and creates a new file with a new name. The formatting and layout never changes, only the file name, and all the files will be housed in the same folder as they accumulate.

    I need some sort of Index/Match macro that will aggregate the rows of data from each file (sum them), even as new files are added to the folder, coming together in one "Aggregate File". The catch is having the dates which vary in each file going forward match the appropriate amounts from each file.

    So, for example, there are three "Cash_Flow" files attached (1-3). I would want a new file that would sum each row with the appropriate month in said new file with the same layout. Once a new file is created, the "Aggregate" file collects the new file information as well. Please let me know if I can clarify things further.



    Any help is greatly appreciated.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by YukonSoDank; 04-18-2019 at 04:21 PM.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    I can't promise a solution, but it would help if you could do a manual mockup of the Aggregate workbook that would show the desired end result using the 3 files you posted. That would be a good start.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Thanks, I've added the desired "Aggregate" mockup. You'll see that it basically adds the three "Cash Flow" files together, but "Cash_Flows.xlsx" doesn't come into the equation until Oct 2019 given that the project didn't start until then. So a dynamic index/match is needed given the date ranges of each project will vary, but I need them to sum...and pull from each project file in the housing folder.

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    I added the values from 10/31/19 from the 3 sheets for the Exports and got a total of 1,402,814. The Aggregate file shows a total of 1,584,333. If I understood correctly what you want to do, the totals don't match.

  5. #5
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    All apologies, I re-uploaded...based on you noticing that error you are understanding my objective correctly.

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    The "Aggregate" file has dates until May/53. The "Cash_Flows.xlsx" has dates until Sep/54. Will you be adding columns to the "Aggregate" file to accommodate May/53 to Sep/54?

  7. #7
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Good question, yes.

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Sorry for the delay. The date formats were a bit of a problem for me so I had to find a workaround. I think I have something that will work for you but the macro will depend on all the files that need to be aggregated to be saved in the same folder and they are to be the only files in that folder. If this will work for you, what is the full path to the folder where the files will be saved?

  9. #9
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    No worries, this one is complex to say the least. I always assumed the files would have to be held in the same folder so that is not issue, nor is the exclusivity of only holding these files.

    I'm dangerous enough to change the housing folder in the macro, but for now let's assume a Desktop folder called "Project Models".

  10. #10
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Try the attached file. I have added the additional necessary columns. Just click the button.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    I don't get an error, but nothing happens. The three "Cash Flow" files are saved in a Desktop folder named "Project Models" and macros are enabled in the "Aggregate" file you created.

  12. #12
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    It worked for me on the 3 files you posted. Step through the macro by pressing the F8 key. Each time you press the key, the macro will execute one line of code at a time. When you reach the line that opens the file and press F8, you should see the file that is opened listed in the left hand pane. Try this out and see if the files are being opened.

  13. #13
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    It keeps telling me that "Cash Flows.xlsx" can't be found but all three files are saved in a desktop file that I even renamed "Test" to match your original code. I've tried opening each file and resaving in said "Test" folder.

  14. #14
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Ok, I saved the "Aggregate" file in the same folder that houses the "Cash Flow" files ('Test'). It worked!

    But...as an experiment I changed some cells in one of the cash flow files and resaved it. When I re-open the Aggregate file and re-run the macro I get the same error as before?

  15. #15
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    I restarted the entire process on another computer thinking this might be a version compatibility issue but I get the same error. I posted a screenshot of this error.

  16. #16
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Try creating a folder named "Project Models" in the C:\ Drive and then replace the previous macro with the one below:
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    So I was able to fix the code (see below) and it works nearly flawlessly...the problem now is that each time the macro runs it adds to the previous iteration,
    i.e., if I run the macro again and again it accumulates the numbers.

    Please Login or Register  to view this content.
    Sub updateTotals()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Dim wkbSource As String, sPath As String
    Dim lCol As Long, desWs As Worksheet, srcWS As Worksheet, fDateCol As Long, x As Long, y As Long, strdate As String
    y = 4
    Set desWs = ThisWorkbook.Sheets("Summary")
    sPath = Environ("USERPROFILE") & "\desktop\Test\"
    wkbSource = Dir(sPath & "*.xlsx")
    Do While Len(wkbSource) > 0
    If wkbSource <> ThisWorkbook.Name Then
    Set srcWS = Workbooks.Open(sPath & wkbSource).Sheets("Cash Flow")
    With srcWS
    .Range("B1").Formula = "=TEXT(LEFT(D2,FIND(""/"",TEXT(D2,""mm/dd/yyyy""),4)),""mm/dd/yy"")"
    strdate = .Range("B1")
    lCol = desWs.Cells(1, desWs.Columns.Count).End(xlToLeft).Column - 1
    fDateCol = desWs.Rows(2).Find(Format(.Range("B1").Value2, "m/dd/yy"), LookIn:=xlValues, lookat:=xlWhole).Column
    For x = fDateCol To lCol
    With desWs
    On Error Resume Next
    .Cells(5, x) = .Cells(5, x) + srcWS.Cells(5, y)
    .Cells(6, x) = .Cells(6, x) + srcWS.Cells(6, y)
    .Cells(10, x) = .Cells(10, x) + srcWS.Cells(10, y)
    .Cells(11, x) = .Cells(11, x) + srcWS.Cells(11, y)
    y = y + 1
    End With
    Next x
    End With
    y = 4
    srcWS.Parent.Close False
    End If
    wkbSource = Dir
    Loop
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    End Sub
    Please Login or Register  to view this content.

  18. #18
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    If you look at the macro in Post# 16 you will see that I added this line of code
    Please Login or Register  to view this content.
    Add this line in the same location in the original macro. By the way, what did you do to fix the code?

  19. #19
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Adding that portion works perfect!

    In the previous post I changed this line slightly:
    Set srcWS = Workbooks.Open(sPath & wkbSource).Sheets("Cash Flow")

  20. #20
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Glad it all worked out.

  21. #21
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    And I as well, this was a huge help. One more thing of course...you'll notice there's a "Begin" date in column C. How would I add that to the code where if one or more cells in that column were populated with an amount? I realize the "Begin" date would likely be at the beginning of the month rather than the end like the others, so I'm thinking those amounts (ideally) would land in the month with which they associate...in other words, if a "Cash Flow" file has a Begin amount in column C associated with 10/1/19 it would land in the 10/31/19 column on the Aggregate file.

  22. #22
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Are you saying that you want to add any amount in column C to the amount in the month with which it is associated?

  23. #23
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Yes, exactly.
    Attached Images Attached Images
    Last edited by YukonSoDank; 04-26-2019 at 09:49 AM. Reason: New Screenshot

  24. #24
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Try:
    Please Login or Register  to view this content.

  25. #25
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    I get the error shown in the screenshot that I attached.

  26. #26
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Nevermind, I re-created your file path names and it seems to work perfectly. Cheers! Many thanks as always.

  27. #27
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    It seems to be one column off.

    See the "New" attachments.
    Attached Files Attached Files

  28. #28
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Change y=4 to y=5 near the top of the macro.

  29. #29
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Perfect, so far so good...two thumbs up.

  30. #30
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Glad it worked out.

  31. #31
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Got another doozie...let's say each "Cash Flow" file also contains a tab called "Input" (I have attached).

    In the "Aggregate" file I would like to create an "Input" tab that takes the average of the light blue numbers from each file.

    The dark blue numbers are formulas so they remain unchanged and would exist in this rollup of all the Input tabs in each file.

    Ideally, the end product would contain the "Aggregate" tab that so far works well adding all the "Monthly Cash Flow" amounts together from each file, but in addition an "Input" tab that averages the light blue inputs from each "Input" tab.
    Attached Files Attached Files

  32. #32
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    For clarification: You want an "Input" tab in the "Aggregate" file identical to the one you posted. Then you want to average the values in each blue cell of each "Cash Flow" file. For example, in B6 you have "Solar Size kW DC" with a value of 2000.00 in C6. You want to add the C6 values from each "Cash Flow" file and place the average in C6 of the "Input" tab in the "Aggregate" file. You want to do this for all the light blue cells. If this is correct, could you post 3 new "Cash Flow" files that contain the "Input" tab as well as the "Monthly Cash Flow" tab with data to make it easier to test a possible solution?
    Last edited by Mumps1; 05-03-2019 at 08:41 AM.

  33. #33
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Yes, each "Cash Flow" file would contain an "Input" tab. The "Input" tab of the "Aggregate" file would then average the light blue cells found in each "Input" tab of the "Cash Flow" files.

    I will post some new files as you described here shortly.

  34. #34
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Ok, here are the files. You'll notice the Cash Flow files have changed a bit, but your code still works.
    Attached Files Attached Files

  35. #35
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    I'll need a little time to work on this. I'm going out of town until Sunday so I'll work on it when I get back.

  36. #36
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Great, thanks so much!

  37. #37
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Try this revised code.
    Please Login or Register  to view this content.

  38. #38
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Wow...so far so good...awesome as always!

    One minor quirk..is there a way to eliminate the "update links" prompt from appearing? If 50 cash flow files accumulate in the folder it will appear 50 times and the user will have to click through each one.

  39. #39
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Replace this line of code:
    Please Login or Register  to view this content.
    with this one:
    Please Login or Register  to view this content.

  40. #40
    Registered User
    Join Date
    04-02-2019
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    74

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    Perfect, thanks!

  41. #41
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Need a Macro to Create a Dynamic Index/Match among Cumulated Files

    You're welcome.

+ 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. [SOLVED] Create List - Index Match or Index Aggregate or other?
    By bambamclint in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 02-10-2019, 01:30 PM
  2. Dynamic Index Match Match with Indirect
    By apzoe in forum Excel General
    Replies: 2
    Last Post: 01-01-2019, 06:32 PM
  3. [SOLVED] convert index and match formula in a macro for a big dynamic spreadsheet
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-25-2017, 08:04 PM
  4. Index/Match - Dynamic Index Range with Hlookup
    By WassimJMP in forum Excel General
    Replies: 3
    Last Post: 02-16-2016, 12:24 PM
  5. [SOLVED] INDEX MATCH, MATCH and ADD for a dynamic scatter gram chart
    By julesmctavish in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-12-2016, 10:40 AM
  6. Replies: 6
    Last Post: 09-09-2014, 02:25 PM
  7. Replies: 6
    Last Post: 11-08-2013, 10:29 PM

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