Search code examples
pythonexcelconditional-formatting

Python Excel Worksheet Conditional Formatting Based Off Of Another Sheet


I have an Excel Workbook with two sheets: Sheet 1 and Sheet 2. I want to color format the cells in column 'B' within Sheet1 based off of column Sheet2 'D'.

worksheet.conditional_format("'Sheet1'!B2:C999",
                             {"type": "formula",
                              "criteria": '=Sheet2!($D2=1)',
                              "format": format1
                             }

I have this code working on the same sheet, so I know I am very close, but when trying to format it for another I get a very generic 'NoneType' error.


Solution

  • After banging my head against the wall for hours, I found the solution in only a few minutes. Here is the solution:

    worksheet.conditional_format('B2:C999', {'type': 'formula',
                                           'criteria': '=Sheet2!$D2=1', 
                                           'format': format1})