Search code examples
excelexcel-formulaexcel-2010

Fill na cells in one column with another column in Excel


Given an excel sample data as follows:

enter image description here

For NA cells in column B (which means B3 and B5), I'll need to fill with values in column A.

enter image description here

I write a simple formula for cell B3: =IF(ISNA(B3),A3,B3) (equivalent to df['b'].fillna(df['a']) in Pandas), but returns 0. How could I write a proper formula to solve this issue? Thanks.

The expected result should be like this:

enter image description here


Solution

  • A cell can contain either a value or a formula, which is why you should create an extra column for the result. NA in excel is an error code and does not indicate that a cell is blank. You should use the formula =IF(ISBLANK(B3),A3,B3) in column C