View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.misc
JLatham
 
Posts: n/a
Default Ignoring error in cells

Here is the solution to include columns A through H. That's as far as we can
take this using nested IF() statements due to the built in limit of 7 nested
functions.

The first two columns are kind of special cases, as shown by your example
data and result.

For column A to be counted, the value in it simply needs to be greater than
the value in column B.

Column B needs to be both smaller than the value in column A and larger than
the value in column C to count.

For the rest of the series it is just a matter of back tracking to make sure
that the series continues to decline in value from right to left. Any time
that a value goes higher than that of the cell to the right of it, it causes
failure of the test at that point.

Here is the 8-column formula, split at the + symbols for easier reading:
=IF(A2B2,1,0)+
IF(C2<B2,IF(A2B2,1,0),0)+
IF(A2B2,IF(B2C2,1,0),0)+
IF(A2B2,IF(B2C2,IF(C2D2,1,0),0),0)+
IF(A2B2,IF(B2C2,IF(C2D2,IF(D2E2,1,0),0),0),0)+
IF(A2B2,IF(B2C2,IF(C2D2,IF(D2E2,IF(E2F2,1,0), 0),0),0),0)+
IF(A2B2,IF(B2C2,IF(C2D2,IF(D2E2,IF(E2F2,IF(F2 G2,1,0),0),0),0),0),0)+
IF(A2B2,IF(B2C2,IF(C2D2,IF(D2E2,IF(E2F2,IF(F2 G2,IF(G2H2,1,0),0),0),0),0),0),0)

Here it is again so that you can easily cut and paste it:
=IF(A2B2,1,0)+IF(C2<B2,IF(A2B2,1,0),0)+IF(A2B2, IF(B2C2,1,0),0)+IF(A2B2,IF(B2C2,IF(C2D2,1,0),0 ),0)+IF(A2B2,IF(B2C2,IF(C2D2,IF(D2E2,1,0),0),0 ),0)+IF(A2B2,IF(B2C2,IF(C2D2,IF(D2E2,IF(E2F2, 1,0),0),0),0),0)+IF(A2B2,IF(B2C2,IF(C2D2,IF(D2 E2,IF(E2F2,IF(F2G2,1,0),0),0),0),0),0)+IF(A2B2, IF(B2C2,IF(C2D2,IF(D2E2,IF(E2F2,IF(F2G2,IF(G2 H2,1,0),0),0),0),0),0),0)

You can pick up a sample workbook with this solution in it along with a code
solution.

I'm not greatly pleased with the code, it's clumsy, but it does work and it
is easily modified for varying number of columns of data. Not sure how well
it work with fewer than 4 columns of data. That workbook can be downloaded
from my site he
http://www.jlathamsite.com/uploads/SteveC_Sequences.xls - right click and
'save target as' to grab it.

One thing that continues to confuse me is that a sequence like 10 9 10 you
show as a count of 1, but 10 9 8 would be 3, there seems no way to get a
sequence of 2? Somehow I think that the 'answer' to this riddle may be why
the data in the second column has to be handled as a special case.

And you can call me Jerry - most people do.

"SteveC" wrote:

Thanks Latham, there's no urgency. I''m not that good with macros, so I dont'
want you to waste your time. Then again, if this is a challenge that
interests you, I would enjoy seeing it if only to learn something. Thanks
again!

"JLatham" wrote:

SteveC, Let me look at your questions this evening so I can hopefully come up
with a one-answer-answers-all answer. We're going to be limited in the
current method by the nested function limit in Excel - 7 nested functions.

The basic premise of the current formula was that if the value to the right
of a cell was greater than the current cell (i.e. A1 B1) then set the
result to 1, otherwise set it to zero. The complication comes in when you
realize that any time the constant decrease in values from left to right is
interrupted that you don't/can't count any further at all even if you have an
apparent valid sequence later on: the 10 7 10 9 situation: the second 10
nullifies any further 'valid' sequences.

If you don't mind working with VBA macros, I think it would be easier to
code up a generic solution to this problem than to try to extend the logic
through nested IF statements.

Besides, nested IF's give me a headache <g

"SteveC" wrote:

For this data in row 20, ColM - ColT
17.7% 16.5% 15.2% 14.8% 14.3% 12.5% #DIV/0! #DIV/0! #DIV/0!

this formula:
=IF(M20N20,1,0)+IF(O20<N20,IF(M20N20,1,0),0)+IF( N20O20,IF(M20N20,1,0),0)+IF(O20P20,IF(N20O20,I F(M20N20,1,0),0),0)+IF(P20Q20,IF(O20P20,IF(N20 O20,IF(M20N20,1,0),0),0),0)+IF(Q20R20,IF(P20Q20 ,IF(O20P20,IF(N20O20,IF(M20N20,1,0),0),0),0),0) +IF(R20S20,IF(Q20R20,IF(P20Q20,IF(O20P20,IF(N2 0O20,IF(M20N20,1,0),0),0),0),0),0)+IF(S20T20,IF (R20S20,IF(Q20R20,IF(P20Q20,IF(O20P20,IF(N20O 20,IF(M20N20,1,0),0),0),0),0),0),0)

returns an error

Is there away to still count the consecutive improvements in the first few
columns?

The prior post where I suggested returning a 0 if an error is discovered
wouldn't work...