JenniferMurphy
Well-known Member
- Joined
- Jul 23, 2011
- Messages
- 2,687
- Office Version
- 365
- Platform
- Windows
I am working on a fairly simple UDF to calculate weighted ratings. The expression in the worksheet is:
where both Weights and Ratings are ranges.
This vba code works:
but this gets a Value error:
What do I need to do to be able to do in the UDF the calculation that works in the sheet?
Thanks
Excel Formula:
=SUM(Weights*(Ratings<>0))
This vba code works:
VBA Code:
Public Function WtdRtgS(prRatings As Range, prWeights As Range) As Double
Dim SumWts As Double
SumWts = Application.WorksheetFunction.Sum(prWeights)
VBA Code:
SumWts = Application.WorksheetFunction.Sum(prWeights * (prWeights <> 0))
Thanks