How to use SELECT CASE statement
Function Grade(score) Select Case score Case Is < 60 Grade = "F" Case 61 To 64 Grade = "D" Case 65 To 69 Grade = "D+" Case 70 To 74 Grade = "C" Case 75 To 79 Grade = "C+" Case 80 To 84 Grade = "B" Case 85 To 89 Grade = "B+" Case 90 To 94 Grade = "A" Case Else Grade = "A+" End Select End Function
The SELECT CASE statement allows you to compare an expression to multiple values.
It is similar to the IF THEN ELSE statement except that the IF THEN ELSE statement can evaluate multiple expressions. The SELECT CASE statement evaluates one expression.
The User Defined Function above compares the score to several criteria and returns the corresponding grade.
The UDF is entered in column D and takes the score from column C and returns the grade.
UDF in cell D3:
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form