View Single Post
  #16   Report Post  
Posted to microsoft.public.excel.programming
Diana[_5_] Diana[_5_] is offline
external usenet poster
 
Posts: 24
Default Is there more efficient formula?

Thanks for the suggestion but it still doesn't change the
result.... This is the formula (with the same logic) that
works:

Sub Test()
Dim Value(1 To 4)
Dim A(1 To 4)
Dim Total As Double
Dim TotalA As Double
Dim WeightedAvg As Double
Dim i As Integer

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


A(1) = 0.5
A(2) = 0.3
A(3) = 0
A(4) = 0.1

For i = 1 To 4
TotalA = TotalA + A(i) * Value(i)
If A(i) 0 Then Total = Total + Value(i)
Next i

WeightedAvg = TotalA / Total

MsgBox WeightedAvg

End Sub

-----Original Message-----
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.aspx?scid=kb;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


.