View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default subscript out of range - how to determine

Another way would be

Function SumAbs(y0 As Range)
Dim cell as Variant, v as Variant
v = y0.value
for each cell in v
if isnumeric(cell) then
SumAbs = SumAbs + Abs(cell)
end if
Next
End function

v is a variant array holding the values in your range and can be traversed
much faster than a range of cells, even if you cut down on the number of
columns examined.


Also, I am sure Bob edited your code and overlooked correcting you, but when
the code says

Dim A, B As Double (assumes you want A and B to be doubles)

this actually is the equivalent of
Dim A as Variant, B as Double

You have to type each variable individually.

--
Regards,
Tom Ogilvy


"JohnJack" wrote:

Thanks a ton. Works great.
Cheers,

Jack


On Feb 14, 12:08 pm, "Bob Phillips" wrote:
Function SumAbs(y0 As Range)
'this function will return the sum absolute value from all the cells in the
range provided

Dim A, B As Double
Dim Counter As Long, Counter2 As Long
Dim oCol As Range

For Each oCol In y0.Columns
If oCol.Cells(1, 1) = "" Then
Exit For
End If
A = A + 1
Next oCol

B = Application.Count(y0) / A

SumAbs = 0

For Counter2 = 1 To A
For Counter = 1 To B

SumAbs = SumAbs + Abs(y0(Counter, Counter2))

Next Counter
Next Counter2

End Function