2 comparison operators in select case at same level without loss in precision

R

rd

Hi,

I am not an expert programmer. I want to know if it is possible to use two
comparison operators in a select case statement, at the same level? I want
the code in a UDF function to test whether a certain ratio falls between 2
values, say, 30<x<=40, if it does the function returns a value ; otherwise,
it should test for next higher level 40<x<=50, etc.

Using If...Then...Else code, the UDF looks like this:

Public Function SlidingCommission(pLossRatio As Single) As Single

If pLossRatio <= 0.50 Then
SlidingCommission = 0.275 'Maximium Commission is 27.50%
ElseIf pLossRatio > 0.50 And pLossRatio <= 0.6 Then
SlidingCommission = 0.22
ElseIf pLossRatio > 0.6 And pLossRatio <= 0.7 Then
SlidingCommission = 0.175 .
 
G

Guest

Hi,

This will give the accuracy you require:-

If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
If Not Intersect(Target, Range("A1:A30")) Is Nothing Then
Select Case Target.Value
Case Is > 0.6
SlidingCommission = 0.175
Case Is > 0.5
SlidingCommission = 0.22
Case Is > 0
SlidingCommission = 0.275
End Select
End If
Target.Offset(0, 1).Value = SlidingCommission
End Sub

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top