Return last value in a row > 0

adamash

Board Regular
Joined
Jun 24, 2011
Messages
70
Guys.

I have a query for you.

I have a row of values. I need a formula that will return the last value > 0

For example;

0 12 32 25 18 0 0 0 0 0

The formula should return 18

Is this possible in Excel?

Many thanks,
Adam
 
Or a simpler way ;)

=max(range)

The request was for the last (furthest to the right) value that is > 0
This is not necessarily the largest # in the range.

Given the OP's example..
max(0 12 32 25 18 0 0 0 0 0)
Max would return 32
OP wants 18
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Guys.

I have a query for you.

I have a row of values. I need a formula that will return the last value > 0

For example;

0 12 32 25 18 0 0 0 0 0

The formula should return 18

Is this possible in Excel?

Many thanks,
Adam
Here's another one...

=LOOKUP(2,1/A1:J1,A1:J1)
 
Upvote 0
Even though you now have all the answers you need, I have modifed my original macro to reflect teh true nature of your question

Code:
Sub test()
'Assuming your data starts in cell A2
Dim IntCol As Long
Dim LCol As Long, LCol1 As Long
Dim LRow As Long
Dim CuVal As Long
Dim i As Long
IntCol = 1
CuVal = 0
LCol = Sheets("SheetName").Cells(1, Columns.Count).End(xlToLeft).Column
LCol1 = Sheets("SheetName").Cells(1, Columns.Count).End(xlToLeft).Column + 1
LRow = Sheets("SheetName").Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LRow
    Do
    
        If Not Sheets("SheetName").Cells(i, IntCol) = 0 Then
        
        CuVal = Sheets("SheetName").Cells(i, IntCol)
        
        End If
    
    IntCol = IntCol + 1
    Loop Until IntCol = LCol
Sheets("SheetName").Cells(i, LCol1).Value = CuVal
Next i
End Sub

Regards
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top