View Single Post
  #12   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?

This is a smart way of thinking but when I cut and paste
the formula I get zero no matter what A,B,C and D is...

-----Original Message-----
Try this, Diana. Let me know if you have problems. I

tested it against
yours and got the same answers every time.

Mark

Public Function WeightedAvg(A, B, C, D)

Dim ValueA, ValueB, ValueC, ValueD, Total As Double
Dim Vals(3) As Double
Dim Per(3) As Double
Dim Sums(3) As Double

On Error GoTo Handle

Vals(0) = A
Vals(1) = B
Vals(2) = C
Vals(3) = D

Per(0) = 0.5
Per(1) = 0.25
Per(2) = 0.15
Per(3) = 0.1

IsTot = False

For x = 0 To 3
If Vals(x) = 0 Then
IsTot = True
End If
Sums(x) = Vals(x) * Per(x)
Next x

y = 0
If IsTot = True Then
For x = 0 To 3
If Sums(x) < 0 Then
y = y + Per(x)
End If
Next x
For x = 0 To 3
Sums(x) = Sums(x) / y
Next x
End If

Total = 0
For x = 0 To 3
Total = Total + Sums(x)
Next x

WeightedAvg = Total

Handle:
WeightedAvg = 0

End Function

---
Mark Bigelow
mjbigelow at hotmail dot com
http://hm.imperialoiltx.com

*** Sent via Developersdex http://www.developersdex.com

***
Don't just participate in USENET...get rewarded for it!
.