LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Function Arguments

I have a function that is set up to accept ranges as
arguments, so that I can invoke it from the spreadsheet.
In the function code I loop through the cells of these
ranges.

I would like this function to also accept arrays as
arguments from VBA code. Is there a way to get the
function to work in both cases, whether the arguments are
ranges or arrays?

Here's the function:

Function WtdHarmean2(Numerator, Denominator, Weights)

Application.Volatile

'Create an array of weighted reciprocals
Dim N As Integer
Dim RCount As Integer
Dim SumRecips As Double
Dim SumWeights As Double

SumRecips = 0
SumWeights = 0
N = Weights.Count

For RCount = 1 To N
'Clean up input data to prevent errors
If IsNumeric(Denominator.Cells(RCount).Value) And _
IsNumeric(Numerator.Cells(RCount).Value) And _
Numerator.Cells(RCount).Value < 0 Then

'Data is okay to use: sum the weighted
reciprocals
SumRecips = SumRecips + (Denominator.Cells
(RCount).Value / Numerator.Cells(RCount).Value) *
Weights.Cells(RCount).Value
SumWeights = SumWeights + Weights.Cells
(RCount).Value 'sum weights

Else: 'Don't count the data, assign it a
value and weight of zero
SumRecips = SumRecips + 0
SumWeights = SumWeights + 0
End If
Next RCount

'WtdHarmean2 is the reciprocal of the mean of the
array of reciprocals
WtdHarmean2 = 1 / (SumRecips / SumWeights)

End Function

 
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
Function Has Too Many Arguments tb Excel Worksheet Functions 4 May 19th 10 02:26 AM
function arguments Oregongal35 Excel Discussion (Misc queries) 7 November 14th 08 06:32 PM
IF function with too many arguments ahutyra Excel Worksheet Functions 3 August 8th 08 02:01 AM
If Function with 3 arguments CIW Excel Worksheet Functions 5 December 5th 06 10:34 AM
Function Arguments Jessica Excel Worksheet Functions 4 September 18th 06 03:05 AM


All times are GMT +1. The time now is 10:20 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"