Home > database >  In MS Excel look for the previous cell that is a number in a column
In MS Excel look for the previous cell that is a number in a column

Time:08-27

For the same company (in this case Company A), I want to change the "NA" to the last available number. For example, cell D3 and D4 are NA, so I want it both change to last available number (which is "1" in cell D2). If they are different company (like cell B7 and B6), then return the original "NA".

I tired =IF(C3= "NA", INDEX(C$2:C$11,MATCH(TRUE,ISNUMBER(C$2:C$11),0),1),C3), but it does not work as it returns #N/A. Please can anyone help? Thanks!

Image enter image description here

CodePudding user response:

It seems to work for me though? Recreated the data for company A and replaced "," for ";" as it is the separator I use. Additionally I removed the spaces in the formula as I never use them in Excel.

As a result the formula gives the wanted result.

Does your Excel support the formulas you are trying to use?

enter image description here

CodePudding user response:

The column codes of your verbal description do not match the column codes of your screenshot. So just to be clear, in the following answer I will refer to the column codes as given in your screenshot.

The formula that you included does compute the result for me, by the way it is set up, it does not calculate what you described verbally.

In its form as written in your question, the formula ignores the company name and when faced with an 'NA' value, it returns the first number it finds starting from the top.

If I understand correctly, you want the formula to only take into consideration numbers associated with the same company name in column A, and when faced with 'NA', return the "most recent" number it finds for that company starting from the current row going up (given that date values are in order).

The following formula incorporates those features when pasted into cell D2:

=IFERROR(INDEX(FILTER($C$2:$C2,($A$2:$A2=$A2)*(ISNUMBER($C$2:$C2))),SUM(($A$2:$A2=$A2)*(ISNUMBER($C$2:$C2)))),"NA")

With this solution, the company names do not have to be in order, yet the date values do. The formula can be adjusted for cases where neither company names, nor date values are in order.

Note that the FILTER function is only available in Excel for Microsoft 365 and Excel 2021. In Excel 2019, Excel 2016 and earlier versions, it is not supported.

  • Related