Results 1 to 3 of 3

Thread: consolidate identical reports

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    Hello Amy
    Welcome to ExcelFox

    Quote Originally Posted by Amy View Post
    ..... Is there a way to consolidate them in or report using EXCEL VBA.Screenshot 2024-11-26 213815.png
    As far as a Excel VBA solution is concerned, the simple answer to that is Yes, or perhaps yeses – In Excel VBA there are endless possibilities and permutations to do something like that.
    It is difficult to give you more specific help without knowing something about you, your Excel VBA knowledge and abilities, and more precise details of the final requirement, typical actual data sizes etc. etc.


    If your data has a very tidy simple ordered structure as your sample and explanation suggests might be the case, then it’s worth pointing out perhaps that a non VBA solution may be a much better alternative, for example , as Sir Moderator, sandy666, has shown you . Other non VBA solutions may also be worth considering. (I am personally less familiar with non VBA solutions, but even a simple formula or formulas might be sometimes sufficient)




    Please note, it is easier for us to work on a sample workbook, rather than an image, since then we do not have to construct a workbook ourselves in order to show you examples, and it is then also easier for us to investigate solutions.




    Some example solutions, formula and VBA
    As sandy666 has given a solution with an example file, I will do a short VBA / formula solution example as a comparison using similar data.
    But I will put the results in a new output range so as not to disturb or destroy that existing Power Query solution.

    This/these is/are an example of a formula and VBA solution.

    I think it helps with this demonstration to include another sample data rage which I will include in a separate new workbook, Book2.xls . For the demonstration solution to work, you will need to download both workbooks, Book1.xlsx and Book2.xls to the same place , (but a final solution does not have to have this restriction: Files can be anywhere as long as you know where.
    Note that it is only necessary to have Book1.xlsx open for these demonstrations to work. The other workbook, Book2.xls , can be open or closed. This is because I am applying a closed workbook reference to retrieve values from a closed workbook, which is possible in Excel without VBA. (I am creating the closed workbook formula for convenience with VBA, but it is not necessary: you can add those formulas manually).


    So, this first solution, Sub FormulaInWithVBA(), puts the same relative reference formula across the output results range, then saves the file.
    Code:
     Sub FormulaInWithVBA()    '  https://www.excelfox.com/forum/showthread.php/2991-consolidate-identical-reports
    ' Let Workbooks("Book1.xlsx").Worksheets("Sheet1").Range("C21:D23") = "=SUM(C3,G3,'C:\Users\acer\Desktop\[Book2.xls]Tabelle1'!C3)"
     Let Workbooks("Book1.xlsx").Worksheets("Sheet1").Range("C21:D23") = "=SUM(C3,G3,'" & ThisWorkbook.Path & "\[Book2.xls]Tabelle1'!C3)"
     Workbooks("Book1.xlsx").Save
    End Sub
    Finally you have a formula solution, as you only are using the coding once to put the formulas in: You could do the same by writing the formulas in yourself manually instead



    The second solution, Sub VBA_ClosedWorkbookFormulaSolution() , is almost the same, but it simply converts the formulas to values.
    Code:
    Sub VBA_ClosedWorkbookFormulaSolution()  '  https://www.excelfox.com/forum/showthread.php/2991-consolidate-identical-reports
    ' Let Workbooks("Book1.xlsx").Worksheets("Sheet1").Range("C21:D23") = "=SUM(C3,G3,'C:\Users\acer\Desktop\[Book2.xls]Tabelle1'!C3)"
     Let Workbooks("Book1.xlsx").Worksheets("Sheet1").Range("C21:D23") = "=SUM(C3,G3,'" & ThisWorkbook.Path & "\[Book2.xls]Tabelle1'!C3)"
     Let Workbooks("Book1.xlsx").Worksheets("Sheet1").Range("C21:D23") = Workbooks("Book1.xlsx").Worksheets("Sheet1").Range("C21:D23").Value
     Workbooks("Book1.xlsx").Save
    End Sub
    This second solution is just one of an infinite number or possibly VBA solutions. One advantage of this solution is that the data workbooks do not have to be open





    Alan
    Attached Files Attached Files
    Last edited by DocAElstein; 11-28-2024 at 05:11 PM.

Similar Threads

  1. PQ - Consolidate two tables
    By sandy666 in forum ETL PQ Tips and Tricks
    Replies: 0
    Last Post: 05-09-2020, 08:03 PM
  2. Building reports
    By papabill in forum Access Help
    Replies: 3
    Last Post: 04-12-2015, 03:40 AM
  3. Displaying dates in reports as MM/DD
    By papabill in forum Access Help
    Replies: 1
    Last Post: 02-26-2015, 06:16 AM
  4. Replies: 41
    Last Post: 08-22-2013, 01:05 AM
  5. Macro to match identical names and allocate ID's
    By foncesa in forum Excel Help
    Replies: 8
    Last Post: 06-23-2013, 12:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •