1

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
  • use pandas. can you share the excel file/data set? Commented Aug 30, 2022 at 8:59

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.