Function Mfreq(sFunction As String, ParamArray v()) As Variant
'Mfreq performs the function sFunction on last given column per
'combination of the previous ones. Example:
'Now select D1:F3 and array-enter
'=Mfreq("sum",A1:A5,B1:B5,C1:C5) and you will get
'Reverse("moc.liborplus.www") V0.4 15-Oct-2009
Dim i As Long, j As Long, k As Long, lvdim As Long
Dim s As String, sC As String
With Application.WorksheetFunction
Set obj = CreateObject("Scripting.Dictionary")
v(0) = .Transpose(.Transpose(v(0)))
Mfreq = CVErr(xlErrValue)
If lvdim > 100 Then lvdim = 100 'Let us start with small dim
ReDim vR(0 To UBound(v), 1 To lvdim)
For i = 1 To UBound(v(0))
For j = 1 To UBound(v) - 1
v(j) = .Transpose(.Transpose(v(j)))
Select Case LCase(sFunction)
vR(UBound(v), obj.Item(s)) = vR(UBound(v), _
obj.Item(s)) + v(UBound(v))(i, 1)
If vR(UBound(v), obj.Item(s)) < v(UBound(v))(i, 1) Then
vR(UBound(v), obj.Item(s)) = v(UBound(v))(i, 1)
If vR(UBound(v), obj.Item(s)) > v(UBound(v))(i, 1) Then
vR(UBound(v), obj.Item(s)) = v(UBound(v))(i, 1)
For j = 0 To UBound(v) - 1
vR(UBound(v), k) = v(UBound(v))(i, 1)
'Reduce result array to used area
If k > 0 Then ReDim Preserve vR(0 To UBound(v), 1 To k)
'Here we normally get if we breach Ubound(vR,2)
'So we need to increase last dimension
If lvdim > UBound(v(0)) Then lvdim = UBound(v(0))
ReDim Preserve vR(0 To UBound(v), 1 To lvdim)
Resume 'Back to statement which caused error