Find highest value in sequences of numbers

ddub25

Well-known Member
Joined
Jan 11, 2007
Messages
617
Office Version
  1. 2019
Platform
  1. Windows
In the table below I want to analyse the 'Results' column for the highest value in each sequence of positive numbers between the 0's. For example, in the first 3 rows there are values of 50, 169, 82 before a 0 appears. 169 is the highest value and so I want this value to be returned in the 'Largest Values' column. In row 5 of 'Results', the sequence starts again (after a 0) with a value of 47, but only lasts one row before a 0 appears and so 47 would be returned.

The largest values don't have to be returned at the bottom of their sequence of positive numbers, this is just where I have put them for ease of communication. They could just be outputted starting in row 1 of 'Largest Values' - which ever is the easiest way to do it.

Having tried different formulas, I can't come up with anything sophisticated enough to do the job. Can anyone point me in the right direction?

Thanks.

ResultsLargest
Values
50
169
82169
0
4747
0
63
112112
0
57
42
322
208322
0
0
0
103
28
39
281
249281

<colgroup><col span="2"></colgroup><tbody>
</tbody>
 
pgc

I think you mean

B2 (just adjusting the ranges to suit)
=IF(AND(A2<>0,A3=0),MAX(INDEX(A:A,1+IFERROR(MATCH(2,1/(A$1:A1=0)),1)):A2),"")

M.
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi Pedro,

Yes I noticed that you copied the formula from row 4.
Your formula is much simpler. My formula was unnecessarily complicated - sometimes we do not see the obvious.

M.
 
Upvote 0
@pgc01, @Marcelo Branco

You have to mention that this excellent formula:

=IF(AND(A2<>0,A3=0),MAX(INDEX(A:A,1+IFERROR(MATCH(2,1/(A$1:A1=0)),1)):A2),"")

is CSE formula.
 
Upvote 0
Ingolf

You are right, the formula above requires CSE.

Alternatively i suggest this new version (no CSE)
B2 copied down
=IF(AND(A2<>0,A3=0),MAX(INDEX(A:A,1+IFERROR(LOOKUP(2,1/(A$1:A1=0),ROW(A$1:A1)),1)):A2),"")

M.
 
Upvote 0
Hi

Just tested. Didn't seem to need CSE. Could you post an example where it's needed?
 
Upvote 0
Hi Pedro

Am i missing the obvious? :) (maybe using a wrong formula)

I tested without CSE (see post #11)
B2
=IF(AND(A2<>0,A3=0),MAX(INDEX(A:A,1+IFERROR(MATCH(2,1/(A$1:A1=0)),1)):A2),"")

and the results were


A
B
1
Results​
Largest Values​
2
50​
3
169​
4
82​
169​
5
0​
6
47​
169​
7
0​
8
63​
9
112​
169​
10
0​
11
57​
12
42​
13
322​
14
208​
322​
15
0​
16
0​
17
0​
18
103​
19
28​
20
39​
21
281​
22
249​
322​

<tbody>
</tbody>


with CSE i got the expected results


A
B
1
Results​
Largest Values​
2
50​
3
169​
4
82​
169​
5
0​
6
47​
47​
7
0​
8
63​
9
112​
112​
10
0​
11
57​
12
42​
13
322​
14
208​
322​
15
0​
16
0​
17
0​
18
103​
19
28​
20
39​
21
281​
22
249​
281​

<tbody>
</tbody>


M.
 
Upvote 0

Forum statistics

Threads
1,214,868
Messages
6,122,005
Members
449,059
Latest member
mtsheetz

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