Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bruce
 
Posts: n/a
Default count cells since last non-zero value

I would like to know (count) the number of cells since the last non-zero value.

An example would be my data is in cells A1:A10 with A10 representing the
most recent value.
Data examople as follows for A1:A10 respectively;

2, 3, 2, 3, 0, 1, 4, 0, 0 ,0

In this example A7 has the most recent non-zero value.
In A11 I want to have a formula that tells me that its been 3 zero data
points since the last value (which is 4).

Rgds,

bruce


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
 
Posts: n/a
Default count cells since last non-zero value

Hi Bruce,

Enter into A11:
=ending_zero_cells(A1:A10)

and define the UDF
Option Explicit

Function ending_zero_cells(r As Range) As Long
Dim rcell As Range
Dim i As Long
i = 0
For Each rcell In r
If rcell.Value = 0 Then
i = i + 1
Else
i = 0
End If
Next rcell
ending_zero_cells = i
End Function

HTH,
Bernd

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bruce
 
Posts: n/a
Default count cells since last non-zero value

Great, works a treat...

Didn't think i would have to resort to VBA but just the same solved my prob.
Gonna think this through now to work out a similar function for the reverse.

i.e. Cells since first non-zero value appeared.

Rgds,

Bruce


" wrote:

Hi Bruce,

Enter into A11:
=ending_zero_cells(A1:A10)

and define the UDF
Option Explicit

Function ending_zero_cells(r As Range) As Long
Dim rcell As Range
Dim i As Long
i = 0
For Each rcell In r
If rcell.Value = 0 Then
i = i + 1
Else
i = 0
End If
Next rcell
ending_zero_cells = i
End Function

HTH,
Bernd


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Aladin Akyurek
 
Posts: n/a
Default count cells since last non-zero value

=ROWS(A2:A10)-MATCH(2,1/(A2:A100))

which must be confirmed with control+shift+enter, not just with enter.


Bruce wrote:
I would like to know (count) the number of cells since the last non-zero value.

An example would be my data is in cells A1:A10 with A10 representing the
most recent value.
Data examople as follows for A1:A10 respectively;

2, 3, 2, 3, 0, 1, 4, 0, 0 ,0

In this example A7 has the most recent non-zero value.
In A11 I want to have a formula that tells me that its been 3 zero data
points since the last value (which is 4).

Rgds,

bruce


  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
 
Posts: n/a
Default count cells since last non-zero value

Hi Bruce,

Option Explicit

Function cells_after_first_nonzero(r As Range) As Long
Dim rcell As Range
Dim i As Long
i = r.Count
For Each rcell In r
i = i - 1
If rcell.Value < 0 Then
cells_after_first_nonzero = i
Exit Function
End If
Next rcell
cells_after_first_nonzero = i
End Function

Have fun,
Bernd



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Domenic
 
Posts: n/a
Default count cells since last non-zero value

Try...

=ROWS(A2:A10)-MATCH(TRUE,A2:A100,0)

....confirmed with CONTROL+SHIFT+ENTER, not just ENTER.

Hope this helps!

In article ,
"Bruce" wrote:

Great, works a treat...

Didn't think i would have to resort to VBA but just the same solved my prob.
Gonna think this through now to work out a similar function for the reverse.

i.e. Cells since first non-zero value appeared.

Rgds,

Bruce

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
count colored cells? DKY Excel Worksheet Functions 21 January 19th 06 09:47 PM
checking that cells have a value before the workbook will close kcdonaldson Excel Worksheet Functions 8 December 5th 05 04:57 PM
Count cells based on date range in another column [email protected] New Users to Excel 1 May 5th 05 08:11 PM
Count cells in one range based on parameters in another range dave roth Excel Worksheet Functions 2 March 29th 05 05:33 PM
Can I count how many grey-filled cells are in a row ? AnthonyG Excel Worksheet Functions 1 February 4th 05 10:08 AM


All times are GMT +1. The time now is 01:32 PM.

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

About Us

"It's about Microsoft Excel"