Python Forum
Updating formulas in Excel - best solution
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Updating formulas in Excel - best solution
#1
Hello,

I'm working on automatizing one report using Python.
In general I have around 20 excel files (.xlsx and .xlms) that I filter base on some criteria and then copy&paste to final report. At the end I dropdown/autofill formulas in the final report (from first row till end) - I assume it will save some time in preparing report.

Is below code best way of dropdown/autofill formula)? I need of course keep reference updates (meaning AO11, AO12, AO13 ect).


# Loop over each row in the range
for row in range(start_row, end_row + 1):
    # Adjust the formula for each row
    adjusted_formula = formula_AP10.replace("10", str(row))  # Update the row reference
    adjusted_formula = adjusted_formula.replace("AO10", f"AO{row}")  # Update the AO10 reference   
    adjusted_formula = adjusted_formula.replace("AN10", f"AN{row}")  # Update the AN10 reference
                   
    # Set the adjusted formula to the current cell in column AP
    MPV1[f"AP{row}"].value = adjusted_formula         
Reply


Messages In This Thread
Updating formulas in Excel - best solution - by MasterOfDestr - Feb-23-2024, 08:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python openyxl not updating Excel file MrBean12 1 393 Mar-03-2024, 12:16 AM
Last Post: MrBean12
  plotting based on the results of mathematical formulas Timur 1 380 Feb-08-2024, 07:22 PM
Last Post: Gribouillis
  Updating sharepoint excel file odd results cubangt 1 913 Nov-03-2023, 05:13 PM
Last Post: noisefloor
  openpyxl insert list with formulas Irv1n 1 1,589 Sep-16-2021, 08:10 AM
Last Post: Irv1n
  Help with a query - to show possible formulas Yanos 1 1,799 Nov-02-2020, 12:18 AM
Last Post: jefsummers
  How to ignore formulas when reading excel file SriMekala 3 6,583 Aug-16-2019, 04:04 PM
Last Post: buran
  python 3 math formulas where to use () Python101 1 2,333 Jun-09-2019, 09:54 PM
Last Post: micseydel
  Business formulas more help needed!! jy0013 4 3,455 Aug-29-2017, 12:21 AM
Last Post: jy0013

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020