Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
rd rd is offline
external usenet poster
 
Posts: 6
Default 2 comparison operators in select case at same level without loss in precision

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 .
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 2 comparison operators in select case at same level without loss i

Hi,

This will give the accuracy you requi-

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

"rd" wrote:

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 .
.
.
End If
End Function

My question is: can a select case be used instead of the If...Then...Else
code without losing precsion.

You input is greatly appreciated.

RD



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparison Operators in formulas Steve P[_2_] Excel Discussion (Misc queries) 1 November 5th 09 11:55 PM
Comparison Operators Devanath Ong Excel Programming 2 June 22nd 06 03:16 PM
Loss of caluclating precision (VBA vs Excel) Alex Excel Discussion (Misc queries) 1 October 13th 05 03:13 PM
Comparison Operators for IF statement. Shams Excel Worksheet Functions 1 February 14th 05 03:35 PM
Using SELECT...CASE with comparison operators? Toby Erkson[_3_] Excel Programming 7 July 14th 04 09:52 PM


All times are GMT +1. The time now is 10:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"