I need to move cell D3 to D4 in excel if cell A3 is not equal to C3 can anyone tell how to do this using python?
Asked
Active
Viewed 20 times
1
-
use pandas. can you share the excel file/data set? – chitown88 Aug 30 '22 at 08:59
1 Answers
0
This will do exactly what you asked for:
import openpyxl
filename = 'table.xlsx'
wb = openpyxl.load_workbook(filename)
ws = wb.active
if ws['A3'] != ws['C3']:
ws['D4'] = ws['D3'].value
ws['D3'] = None
wb.save(filename)
Make sure not to have the file open in Excel while you do this, or you'll get permission errors. If you want to do this dynamically (while you have the file open) you'll have to use pywin32
which is slightly more challenging.

Laguilhoat
- 325
- 1
- 6