View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
keepITcool keepITcool is offline
external usenet poster
 
Posts: 2,253
Default Is there more efficient formula?

Dana

this would work except OP wants to correct
for missing values..e.g. incomplete n series
hence my variation (see earlier post.)

With Application.WorksheetFunction
WeightedAvg = .SumProduct(Weights, Values) / _
.SumProduct(Weights, noNull)
End With


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Dana DeLouis" wrote:

I most likely have done this wrong, but this article suggest the
following formula...

Calculating Weighted Averages
http://support.microsoft.com/default...b;en-us;109211

Sub Test()
Dim Wgt(1 To 4)
Dim n(1 To 4)
Dim WeightedAvg As Double

Wgt(1) = 0.5
Wgt(2) = 0.25
Wgt(3) = 0.15
Wgt(4) = 0.1

n(1) = 10
n(2) = 0
n(3) = 5
n(4) = 30


With WorksheetFunction
WeightedAvg = .SumProduct(n, Wgt) / .Sum(n)
End With

MsgBox WeightedAvg
End Sub