Returns the percentage of numbers in a range that satisfy multiple conditions.

'rgeValues - The range of values.
'sCondition - The condition you want to use.
'iDecimalPlaces - The number of decimal places you want the percentage returned as.

Public Function PERCENTAGEIF(ByVal rgeValues As Range, _
                           ByVal sCondition As String, _
                           ByVal iDecimalPlaces As Integer) As Double

   PERCENTAGEIF = VBA.Round((Application.WorksheetFunction.CountIf(rgeValues, sCondition) / _
                 Application.WorksheetFunction.Count(rgeValues)) * 100, iDecimalPlaces)

End Function

© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext