Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 36
Default How do I create a function that counts number of cells in a series

For example, suppose you have the following data:

P
S
S
P
S
S
S
P
S
S

and you want to count how many "S"s repeat after each "P." That is, you're
looking for output:

"2s" = 2
"3s" = 1

Is there any way to write a function to do that?
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,722
Default How do I create a function that counts number of cells in a series

Create a helper column (B).
In B2:
=IF(A2="P",0,B1+1)

Now, to get your desired answers
2s:
=COUNTIF(B:B,2)
3s:
=COUNTIF(B:B,3)
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Demosthenes" wrote:

For example, suppose you have the following data:

P
S
S
P
S
S
S
P
S
S

and you want to count how many "S"s repeat after each "P." That is, you're
looking for output:

"2s" = 2
"3s" = 1

Is there any way to write a function to do that?

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 751
Default How do I create a function that counts number of cells in aseries

Luke,

This solution will count more 2's than necessary. You have to take
into account that the next value will be 0. So, start with the helper
column suggested by Luke in B2 (assume data in A2:A101):

=IF(A2="P",0,B1+1)

and then,

=SUMPRODUCT((A2:A101=2)*(A3:A102=0))

HTH
Kostis Vezerides

On Aug 3, 4:24*pm, Luke M wrote:
Create a helper column (B).
In B2:
=IF(A2="P",0,B1+1)

Now, to get your desired answers
2s:
=COUNTIF(B:B,2)
3s:
=COUNTIF(B:B,3)
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*



"Demosthenes" wrote:
For example, suppose you have the following data:


P
S
S
P
S
S
S
P
S
S


and you want to count how many "S"s repeat after each "P." That is, you're
looking for output:


"2s" = 2
"3s" = 1


Is there any way to write a function to do that?- Hide quoted text -


- Show quoted text -


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 15,768
Default How do I create a function that counts number of cells in a series

Try this...

Data in the range A2:A11

D1 = S
C2:Cn = 1,2,3,4,5 etc

Enter this array formula** in D2 and copy down as needed:

=SUM(IF(FREQUENCY(IF(A$2:A$11=D$1,ROW(A$2:A$11)),I F(A$2:A$11<D$1,ROW(A$2:A$11)))=C2,1))

** array formulas need to be entered using the key combination of
CTRL,SHIFT,ENTER (not just ENTER). Hold down both the CTRL key and the SHIFT
key then hit ENTER.

This is what the output will be:

...........C..........D
1.....................S
2........1...........0
3........2...........2
4........3...........1
5........4...........0
6........5...........0



--
Biff
Microsoft Excel MVP


"Demosthenes" wrote in message
...
For example, suppose you have the following data:

P
S
S
P
S
S
S
P
S
S

and you want to count how many "S"s repeat after each "P." That is, you're
looking for output:

"2s" = 2
"3s" = 1

Is there any way to write a function to do that?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
HOW DO I CREATE A SERIES INVOLVING CELLS ACROSS ROWS? CNN Excel Discussion (Misc queries) 3 July 24th 08 03:38 AM
Number of Months Counts Jalal Excel Worksheet Functions 3 February 23rd 08 08:19 PM
Need to create a formula that counts dates Craig Excel Discussion (Misc queries) 2 November 28th 07 09:16 AM
a function that counts the number of cells with information zuri125 Excel Worksheet Functions 1 June 7th 06 07:37 AM
a function that counts the amount of cells with information in them zuri125 Excel Discussion (Misc queries) 2 June 7th 06 05:02 AM


All times are GMT +1. The time now is 09:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"