Openpyxl Copying Formula in Specific Column

Viewed 38

I am attempting to pull down a formula located in cell E2 through the rest of the "E" column, but I can't quite figure out how to. My current code adds the cells in the E column to the cells in the "D" column which is not what I want.

Current Code:

#Copy Formulae 
pathway = glob.glob("Updated Workbook.xlsx") #Pulls filename
pathway = ''.join(pathway)
w_b = load_workbook(pathway) #Pulls workbook using filename
w_s = w_b['Sheet 1'] #Sets worksheet to pull formula through
for row, cellObj in enumerate(list(w_s.columns)[4]): #Iterates through the rows to pull formulae down through cells
    if row != 0: #Causes header row to be skipped
        n = '=(D%d*E%d)' % (row + 1, row + 1)
        cellObj.value = n
w_b.save('Copied Formulae.xlsx')
0 Answers
Related