I am in the process of brain storming how to best tackle the below problem. Any input is greatly appreciated.

Sample Excel sheet columns:

```Column A  |  Column B  | Column C
Apple     |  Apple     |
Orange    |  Orange    |
Pear      |  Banana    |
```

I want Excel to tell me whether items in column A and B match or mismatch and display results in column C. The formula I enter in column C would be =IF(A1=B1, "Match", "Mismatch")

On excel, I would just drag the formula to the rest of the cells in column C to apply the formula to them and the result would be:

```Column A  |  Column B  | Column C
Apple     |  Apple     | Match
Orange    |  Orange    | Match
Pear      |  Banana    | Mismatch
```

To automate this using a python script, I tried:

```import openpyxl
Sheet = wb.get_sheet_by_name('Sheet1')
for cellObj in Sheet.columns[2]:
cellObj.value = '=IF(\$A\$1=\$B\$1, "Match", "Mismatch")
wb.save('test.xlsx')
```

This wrote the formula to all cells in column C, however the formula only referenced cell A1 and B1, so result in all cells in column C = Match.

```Column A  |  Column B  | Column C
Apple     |  Apple     | Match
Orange    |  Orange    | Match
Pear      |  Banana    | Match
```

How would you handle this?

Mar 28, 2022 in Database 3,599 views

## 1 answer to this question.

Using python to add formulas to an excel spreadsheet =VLOOKUP(B3|"Settlement Info"! =SUMIFS("Payment and Fees"! \$B\$2:\$R\$2199|17|FALSE) \$B\$2:\$R\$2199|17|FALSE) \$B\$2:\$R\$2199|17|FALSE) \$B\$ "Payment and Fees"! \$I\$2:\$I\$6445 \$B\$2:\$B\$6445|Summary! B3) \$
=+E3-F3-G3-I3. \s=IF(AND(I3>0|I3-N3>=-0.1|I3-N3<=0.1)|"Yes"|"No")

If I continue, the sheet will open with a 0 in the field.

import from xlsxwriter.workbook Workbook

Workbook('test.xlsx') = Workbook('test.xlsx') = Workbook('test.xlsx'
worksheet.write formula
('A2','=VLOOKUP(B3,"Settlement Information")!
\$B\$2:\$R\$2199,17,FALSE)')

workbook.close()
• 23,260 points

## What is the best library in python to deal with excel files?

XlsxWriter and Xlwings are the best, in ...READ MORE

## Write a SQL query to find the names of employees that begin with ‘S’

Select ename From emp Where ename like"s%"; READ MORE

## Excel - Split cell with a delimiter and if delimiter not found get complete cell value to another cell

Select the row or column that you ...READ MORE

## MS Excel - SumProduct formula with Loop

Drag this to the right of cell ...READ MORE

## Excel 2003 - Match Column A with Column B & Column C to correspond to Column B

Write a standard IF formula that compares ...READ MORE

## Excel formula to remove comma, spaces, period and add a text

The steps to accomplish this are as ...READ MORE

## EXCEL: How to automatically add serial number in Excel Table using formula that is immune to filtering / sorting?

That's a great question, and it's a ...READ MORE