Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Function Required

I have a 2,000 row column (A) that contains either positive or negative
numbers.
In an adjacent column (B) I need a user defined function in each row which
counts how many rows preceding the active row in Column A contain unbroken
strings of either positive (or negative) numbers.
So for example the function in cell B2000 would determine that A2000 was,
say, positive, and then return a value that counted how many consecutive
cells preceding A2000 were also positive, before changing to negative.
I am sure I could, eventually, come up with some VBA code that looped until
while counting, but would find a Function much more useful.
As always, all suggestions and assistance will be much appreciated.
MichaelC
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default Function Required

Michael,

Try this:

Public Function NthSignConsecutive(rngInput As Range) As Long

Dim lOffset As Long
Dim bPositive As Boolean
Dim lRow As Long
Dim lCol As Long

'note according to your specs this actually returns one less than the
'total number of consecutive sign numbers since it doesn't count the
'row in which it was entered

'and no error checking or type checking at present

lOffset = -1

bPositive = (rngInput.Value 0)
lRow = rngInput.Row + lOffset
lCol = rngInput.Column

With rngInput.Parent

Do While lRow 0

If (.Cells(lRow, lCol).Value 0) = bPositive Then

NthSignConsecutive = NthSignConsecutive + 1
lRow = lRow - 1

Else

Exit Do

End If

Loop

End With

End Function

Robin Hammond
www.enhanceddatasystems.com

"MichaelC" wrote in message
...
I have a 2,000 row column (A) that contains either positive or negative
numbers.
In an adjacent column (B) I need a user defined function in each row which
counts how many rows preceding the active row in Column A contain unbroken
strings of either positive (or negative) numbers.
So for example the function in cell B2000 would determine that A2000 was,
say, positive, and then return a value that counted how many consecutive
cells preceding A2000 were also positive, before changing to negative.
I am sure I could, eventually, come up with some VBA code that looped
until
while counting, but would find a Function much more useful.
As always, all suggestions and assistance will be much appreciated.
MichaelC



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Function Required

Thank you very much for your detailed response, Robin. The function does
appear in my list. When I enter the function into a cell in the column
adacent to the first column, I am asked for the range, and I enter the column
1 range.
But the answer comes out as #VALUE.
I am not proficient enough to figure out the solution.
I would much appreciate any suggestion to fix this.

"Robin Hammond" wrote:

Michael,

Try this:

Public Function NthSignConsecutive(rngInput As Range) As Long

Dim lOffset As Long
Dim bPositive As Boolean
Dim lRow As Long
Dim lCol As Long

'note according to your specs this actually returns one less than the
'total number of consecutive sign numbers since it doesn't count the
'row in which it was entered

'and no error checking or type checking at present

lOffset = -1

bPositive = (rngInput.Value 0)
lRow = rngInput.Row + lOffset
lCol = rngInput.Column

With rngInput.Parent

Do While lRow 0

If (.Cells(lRow, lCol).Value 0) = bPositive Then

NthSignConsecutive = NthSignConsecutive + 1
lRow = lRow - 1

Else

Exit Do

End If

Loop

End With

End Function

Robin Hammond
www.enhanceddatasystems.com

"MichaelC" wrote in message
...
I have a 2,000 row column (A) that contains either positive or negative
numbers.
In an adjacent column (B) I need a user defined function in each row which
counts how many rows preceding the active row in Column A contain unbroken
strings of either positive (or negative) numbers.
So for example the function in cell B2000 would determine that A2000 was,
say, positive, and then return a value that counted how many consecutive
cells preceding A2000 were also positive, before changing to negative.
I am sure I could, eventually, come up with some VBA code that looped
until
while counting, but would find a Function much more useful.
As always, all suggestions and assistance will be much appreciated.
MichaelC




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default Function Required

Put this in cell b1 and copy it all the way down the length of your data.

=NthSignConsecutive(A1)

Robin Hammond
www.enhanceddatasystems.com

"MichaelC" wrote in message
...
Thank you very much for your detailed response, Robin. The function does
appear in my list. When I enter the function into a cell in the column
adacent to the first column, I am asked for the range, and I enter the
column
1 range.
But the answer comes out as #VALUE.
I am not proficient enough to figure out the solution.
I would much appreciate any suggestion to fix this.

"Robin Hammond" wrote:

Michael,

Try this:

Public Function NthSignConsecutive(rngInput As Range) As Long

Dim lOffset As Long
Dim bPositive As Boolean
Dim lRow As Long
Dim lCol As Long

'note according to your specs this actually returns one less than the
'total number of consecutive sign numbers since it doesn't count the
'row in which it was entered

'and no error checking or type checking at present

lOffset = -1

bPositive = (rngInput.Value 0)
lRow = rngInput.Row + lOffset
lCol = rngInput.Column

With rngInput.Parent

Do While lRow 0

If (.Cells(lRow, lCol).Value 0) = bPositive Then

NthSignConsecutive = NthSignConsecutive + 1
lRow = lRow - 1

Else

Exit Do

End If

Loop

End With

End Function

Robin Hammond
www.enhanceddatasystems.com

"MichaelC" wrote in message
...
I have a 2,000 row column (A) that contains either positive or negative
numbers.
In an adjacent column (B) I need a user defined function in each row
which
counts how many rows preceding the active row in Column A contain
unbroken
strings of either positive (or negative) numbers.
So for example the function in cell B2000 would determine that A2000
was,
say, positive, and then return a value that counted how many
consecutive
cells preceding A2000 were also positive, before changing to negative.
I am sure I could, eventually, come up with some VBA code that looped
until
while counting, but would find a Function much more useful.
As always, all suggestions and assistance will be much appreciated.
MichaelC






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Function Required

Thank you so much Robin - that works like magic. Just visited your website
and am impressed. Now I understand how you appreared to intuit what it was I
was trying to accomplish: to identify the lowest points of an Awesome
Oscillator histogram over a ten year period for a very clunky currency
trading model I am working on.


"Robin Hammond" wrote:

Put this in cell b1 and copy it all the way down the length of your data.

=NthSignConsecutive(A1)

Robin Hammond
www.enhanceddatasystems.com

"MichaelC" wrote in message
...
Thank you very much for your detailed response, Robin. The function does
appear in my list. When I enter the function into a cell in the column
adacent to the first column, I am asked for the range, and I enter the
column
1 range.
But the answer comes out as #VALUE.
I am not proficient enough to figure out the solution.
I would much appreciate any suggestion to fix this.

"Robin Hammond" wrote:

Michael,

Try this:

Public Function NthSignConsecutive(rngInput As Range) As Long

Dim lOffset As Long
Dim bPositive As Boolean
Dim lRow As Long
Dim lCol As Long

'note according to your specs this actually returns one less than the
'total number of consecutive sign numbers since it doesn't count the
'row in which it was entered

'and no error checking or type checking at present

lOffset = -1

bPositive = (rngInput.Value 0)
lRow = rngInput.Row + lOffset
lCol = rngInput.Column

With rngInput.Parent

Do While lRow 0

If (.Cells(lRow, lCol).Value 0) = bPositive Then

NthSignConsecutive = NthSignConsecutive + 1
lRow = lRow - 1

Else

Exit Do

End If

Loop

End With

End Function

Robin Hammond
www.enhanceddatasystems.com

"MichaelC" wrote in message
...
I have a 2,000 row column (A) that contains either positive or negative
numbers.
In an adjacent column (B) I need a user defined function in each row
which
counts how many rows preceding the active row in Column A contain
unbroken
strings of either positive (or negative) numbers.
So for example the function in cell B2000 would determine that A2000
was,
say, positive, and then return a value that counted how many
consecutive
cells preceding A2000 were also positive, before changing to negative.
I am sure I could, eventually, come up with some VBA code that looped
until
while counting, but would find a Function much more useful.
As always, all suggestions and assistance will be much appreciated.
MichaelC






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
If function required Ravi Excel Discussion (Misc queries) 5 October 21st 08 01:09 PM
Function required Padraig Excel Discussion (Misc queries) 1 November 6th 07 05:40 PM
add OR to already nested If function - help required N E Body Excel Worksheet Functions 3 November 12th 06 02:43 AM
Function not working quite as required Harald Staff[_5_] Excel Programming 1 September 15th 03 03:45 PM
Function not working quite as required Bob Phillips[_5_] Excel Programming 1 September 15th 03 01:43 PM


All times are GMT +1. The time now is 06:24 AM.

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"