Untitled
unknown
plain_text
a year ago
944 B
6
Indexable
import win32com.client # Open an instance of Excel excel = win32com.client.Dispatch("Excel.Application") # Make Excel visible (optional) excel.Visible = True # Open the workbook workbook = excel.Workbooks.Open(r'path\to\your\workbook.xlsx') # Run the VBA macro target_row = 10 # Example target row excel.Application.Run("ExtendFormulasToRowN", target_row) # Save and close the workbook workbook.Save() workbook.Close() # Quit Excel excel.Quit() # Release the COM object del excel Sub ExtendFormulasToRowN(targetRow As Long) Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") Dim lastCol As Long lastCol = ws.Cells(2, ws.Columns.Count).End(xlToLeft).Column Dim col As Long For col = 1 To lastCol Dim formula As String formula = ws.Cells(2, col).Formula If formula <> "" Then ws.Cells(targetRow, col).Formula = formula End If Next col End Sub
Editor is loading...
Leave a Comment