ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   count last number appear (https://www.excelbanter.com/excel-worksheet-functions/249071-count-last-number-appear.html)

sierra spiegel

count last number appear
 
How do I count the number of calls it takes a number to repeat? For example: 1 2 3 4 5 6 7 8 1
so it takes 8 calls for number 1 to repeat.

thanks

EggHeadCafe - Software Developer Portal of Choice
Design Pattern Interview Questions Part 3
http://www.eggheadcafe.com/tutorials...interview.aspx

JLatham

count last number appear
 
Assuming that your list of numbers to test for repeats is in column A, and
that you enter the number to check for in cell C1 (your 1 in this case), then
this is the basis for the formula to do the counting:
=MATCH(C1,INDIRECT("A" & MATCH(C1,A:A,0)+1 & ":A65536"),0)-MATCH(C1,A:A,0)+1

But there are a couple of potential errors that would return a #NA! error:
the number you enter in C1 is not in the list at all, or it is not repeated.
This formula will catch those and give you a clear indication of "what's
wrong":
=IF(ISNA(MATCH(C1,A:A,0)),"Not In List",IF(ISNA(MATCH(C1,INDIRECT("A" &
MATCH(C1,A:A,0)+1 & ":A65536"),0)-MATCH(C1,A:A,0)+1),"Not
Repeated",MATCH(C1,INDIRECT("A" & MATCH(C1,A:A,0)+1 &
":A65536"),0)-MATCH(C1,A:A,0)+1))

I used 65536 as the last row number to check when looking for the repeated
number, but any number large enough to encompass the entire list would do as
long as it is not greater than the maximum number of rows in your version of
Excel.

"sierra spiegel" wrote:

How do I count the number of calls it takes a number to repeat? For example: 1 2 3 4 5 6 7 8 1
so it takes 8 calls for number 1 to repeat.

thanks

EggHeadCafe - Software Developer Portal of Choice
Design Pattern Interview Questions Part 3
http://www.eggheadcafe.com/tutorials...interview.aspx
.



All times are GMT +1. The time now is 12:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com