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?
1 Answer
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.