Position of last POSITIVE value in a row

SydneyGeek

MrExcel MVP
Joined
Aug 5, 2003
Messages
12,251
Hi, I'm trying to find the location of the last positive value in a row.
Say the data starts in T12 and goes 0,0,0,0,0,2,2,2,2,4,5,6,7,8,0,0,0...
There may be more than one sequence of positive numbers, but no negative numbers. I want to return the position of the LAST positive value in the row

Any ideas please?

Denis
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi there

How about this code in a standard module: Select cell in row you want to check before running it:

Sub LastPositiveNumber()
If Selection.Cells.Count > 1 Then
MsgBox "Please select one cell in the row you wish to examine"
Exit Sub
End If

Dim i As Integer
For i = 256 To 1 Step -1
If Cells(Selection.Row, i).Value > 0 Then
MsgBox Cells(Selection.Row, i).Address
Exit Sub
End If
Next i
End Sub

regards
Derek
 
Upvote 0
Hi, now I have the reverse end of the problem. I can do it in 2 cells, but how do you get the location of the FIRST non-zero value in a range? The non-zeros will always be positive.

Thanks

Denis
 
Upvote 0
SydneyGeek said:
Hi, now I have the reverse end of the problem. I can do it in 2 cells, but how do you get the location of the FIRST non-zero value in a range? The non-zeros will always be positive.

Thanks

Denis

=MATCH(TRUE,A2:A7>0,0)

which you need to confirm with control+shift+enter instead of just enter.

The position value that you get with this formula is a position within A2:A7, the range of interest.

If you want the native position, you need to extend...

=MATCH(TRUE,A2:A7>0,0)+CELL("Row",A2)-1

still to be confirmed with control+shift+enter.
 
Upvote 0
I've seen formulas like this here before =MATCH(2,1/(T2:T20>0))
and I have tried to figure out how it works, but I don't get this one. Can someone explain how this works.
 
Upvote 0

Forum statistics

Threads
1,215,068
Messages
6,122,950
Members
449,095
Latest member
nmaske

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