Forum Discussion

GRobertsVM's avatar
GRobertsVM
Copper Contributor
Nov 28, 2024

Power Automate/Query Assistance - Add new table in file to bottom of existing/trend assistance

Forgive me if this has been answered elsewhere, I have had a look and not been able to find!

Essentially, I have set up a flow using Power Automate that saves an XL I receive via a scheduled email into a sharepoint location.

 

I have then created an excel document that queries this file in order for me to maintain a daily report.

 

My issue is this.

I am currently trending the data, but the only way I have of doing this is by copy and paste into a separate sheet (adding to the bottom of the previous data each day/week (select timescale) manually) as the data gets overwritten on each data refresh.

 

I'm sure there is, but is there a way via either macro or power automate of me automating this process so that each day the table in the new file is just added to the bottom of the existing??

 

Thanks in advance

3 Replies

  • How about this:

    Using Power Automate:

    1. Create a Flow to Append Data:
      • Trigger: Use the same trigger you have for receiving the email.
      • Action: After saving the Excel file to SharePoint, use the "Get rows" action to read the data from the new Excel file.
      • Action: Use the "Add a row into a table" action to append each row from the new Excel file to your existing Excel file.

    Using Excel Macros:

    1. Open the Excel file where you want to append the data.
    2. Press Alt + F11 to open the VBA editor.
    3. Insert a new module by right-clicking on any of the existing modules or the workbook name, then selecting Insert > Module.
    4. Copy and paste the following VBA code into the module:
    Sub AppendData()
        Dim wsSource As Worksheet
        Dim wsDest As Worksheet
        Dim lastRow As Long
        Dim nextRow As Long
    
        ' Set the source and destination worksheets
        Set wsSource = Workbooks("SourceWorkbook.xlsx").Worksheets("Sheet1")
        Set wsDest = ThisWorkbook.Worksheets("Sheet1")
    
        ' Find the last row in the destination sheet
        lastRow = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Row
    
        ' Find the next empty row in the destination sheet
        nextRow = lastRow + 1
    
        ' Copy data from source to destination
        wsSource.UsedRange.Copy Destination:=wsDest.Cells(nextRow, 1)
    End Sub

     

    1. Modify the code to match your workbook and sheet names.
    2. Run the macro by pressing F5 or assigning it to a button in your Excel sheet.
    • Lorenzo's avatar
      Lorenzo
      Silver Contributor

      Kidd_IpYour Power Automate option looks straightforward and probably enough for this case

  • Lorenzo's avatar
    Lorenzo
    Silver Contributor

    Hi

    Can't help you with Power Automate (not in my subscription) but that shouldn't be too complicated (worst case scenario the https://community.powerplatform.com/forums could assist) to integrate https://www.thebiccountant.com/2016/02/09/how-to-create-a-load-history-or-load-log-in-power-query-or-power-bi/ (similar options exist if you search the Net) to your flow

Resources