The function itself is fine.
However the problem will be in the way you are calling the function.
In VBA, function arguments are passed by reference (ByRef
) by default. This means that the data types in the caller have to be exactly the same as those in the function.
Two choices:
1) Adjust your function to
Public Function MyRateCalc(ByVal rateType As String, ByVal fixedAmount As Long, ByVal minAmount As Long, ByVal rateDollar As Long, ByVal valPerc As Long, ByVal rtValue As Long) As Double
2) Check the caller variable types carefully; they must match exactly.
I prefer approach (1) as it increases program stability (functions cannot unintentionally modify variables in the calling code); even though it's at the expense of a string copy in your case.