Return last non-zero value in Excel

john lilleystone • February 26, 2020

How to retrieve the last value in a row that is not zero

I recently needed to find a formula that returned the last value in a row that wasn't zero. The problem is the value I wanted to return could be in different positions in each row. The answer is LOOKUP. You may be familiar with VLOOKUP or HLOOKUP but you can also use LOOKUP by itself. The screen show below shows 3 rows of data all with values in different positions in each row. I need to create a new column called Last Price and pickup the most recent price in the row.

The formula I need to use in column N (Last Price) is as follows;

The formula takes a bit of explaining.

1/(B2:M2<>0) returns a list of TRUE or FALSE, which when divided by 1 converts this list to either 1’s or 0’s. LOOKUP(2, is looking for the number 2 in the list but will never find it because the list only contains 1’s or 0’s. Therefore so the formula will find the last 1 in the list – the remaining part of the formula is the range where the actual values are, so the same lookup range (B2:M2). T aking the 2ND row as an example, the first part of the formula looked in the range B3:M3 and returned 1,1,1,1,1,1, 1 ,0,0,0,0,0. It looked for the value of 2 but couldn’t find it so found the next number down 1 (in bold). The actual values in that range are 7.5,7.5,7.5,7.5,7.5,7.5, 7.5 ,0,0,0,0,0 so the returned value is 7.5

Takes a bit of getting your head round but once you understand what it’s doing it makes sense.

By John Lilleystone January 21, 2021
Remove whitespaces in Excel using the TRIM function.
excel iferror error alternate result
By john lilleystone April 11, 2020
Replace ugly Excel errors returned by a formula with something more appropriate and pleasing to the eye.
excel transpose
By john lilleystone March 14, 2020
Transpose and paste a vertical column of data horizontally into a row
edit hyperlink
By john lilleystone March 14, 2020
Edit a hyperlink in Outlook 2016
emoji symbol
By john lilleystone March 14, 2020
insert an emoji or symbol into your application
sparklines
By john lilleystone March 1, 2020
Add Sparklines to Excel tables to show trends in the data
random numbers randbetween
By john lilleystone March 1, 2020
Use the RANDBETWEEN function in Excel to randomly generate numbers between a specified upper and lower threshold.
DATEADD MSQUERY
By john lilleystone March 1, 2020
Don't waste time manually editing queries to move the date period on one month. This blog explains how to use DATEADD to dynamically shift the dates on one month on each refresh
By john lilleystone February 29, 2020
Import text files into Excel and use the Text to Columns wizard to separate the data into columns
By john lilleystone February 4, 2020
Extract values or strings from a cell from either the left, middle or right part of the cell
Show More