ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Writing a UDF (https://www.excelbanter.com/excel-discussion-misc-queries/191344-writing-udf.html)

Hajiki

Writing a UDF
 
I used this (see below) UDF successfully (can't believe it) but now I want to
do te opposite where 15 =A+, no idea how to write it!

Function Grades(Letter As String) As Integer
Select Case Letter
Case Is = "A+"
Grades = 15
Case Is = "A"
Grades = 14
Case Is = "A-"
Grades = 13
Case Is = "B+"
Grades = 12
Case Is = "B"
Grades = 11
Case Is = "B-"
Grades = 10
Case Is = "C+"
Grades = 9
Case Is = "C"
Grades = 8
Case Is = "C-"
Grades = 7
Case Is = "D+"
Grades = 6
Case Is = "D"
Grades = 5
Case Is = "D-"
Grades = 4
Case Is = "F+"
Grades = 3
Case Is = "F"
Grades = 2
Case Is = "F-"
Grades = 1
End Select
End Function


Pete_UK

Writing a UDF
 
You don't really need a UDF - you can set up a table somewhere
consisting of the grade numbers and the grade letters (for example in
X1:Y15 and looking like this:

15 A+
14 A
13 A-
12 B+

and so on, and then use this formula:

=VLOOKUP(A1,X$1:Y$15,2,0)

to get the grade letters from a grade number in A1 (for example).

You could use the same table with an INDEX/MATCH combination instead
of your UDF.

Hope this helps.

Pete

On Jun 16, 11:40*am, Hajiki wrote:
I used this (see below) UDF successfully (can't believe it) but now I want to
do te opposite where 15 =A+, no idea how to write it!

Function Grades(Letter As String) As Integer
Select Case Letter
* *Case Is = "A+"
* * * *Grades = 15
* *Case Is = "A"
* * * *Grades = 14
* *Case Is = "A-"
* * * *Grades = 13
* *Case Is = "B+"
* * * *Grades = 12
* *Case Is = "B"
* * * *Grades = 11
* *Case Is = "B-"
* * * *Grades = 10
* *Case Is = "C+"
* * * *Grades = 9
* *Case Is = "C"
* * * *Grades = 8
* *Case Is = "C-"
* * * *Grades = 7
* *Case Is = "D+"
* * * *Grades = 6
* *Case Is = "D"
* * * *Grades = 5
* *Case Is = "D-"
* * * *Grades = 4
* *Case Is = "F+"
* * * *Grades = 3
* *Case Is = "F"
* * * *Grades = 2
* *Case Is = "F-"
* * * *Grades = 1
End Select
End Function



edvwvw via OfficeKB.com

Writing a UDF
 
Hajiki wrote:
I used this (see below) UDF successfully (can't believe it) but now I want to
do te opposite where 15 =A+, no idea how to write it!

Function Grades(Letter As String) As Integer
Select Case Letter
Case Is = "A+"
Grades = 15
Case Is = "A"
Grades = 14
Case Is = "A-"
Grades = 13
Case Is = "B+"
Grades = 12
Case Is = "B"
Grades = 11
Case Is = "B-"
Grades = 10
Case Is = "C+"
Grades = 9
Case Is = "C"
Grades = 8
Case Is = "C-"
Grades = 7
Case Is = "D+"
Grades = 6
Case Is = "D"
Grades = 5
Case Is = "D-"
Grades = 4
Case Is = "F+"
Grades = 3
Case Is = "F"
Grades = 2
Case Is = "F-"
Grades = 1
End Select
End Function



Rather than using a UDF have you considered a LOOOKUP array instead:

=LOOKUP(A1,{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 ;"F-","F","F+","D-","D",
"D+","C-","C","C+","B-","B","B+","A-","A","A+","RE-ENTER DATA"})

this error checks for scores over 15


where the score is in A1 - you can drag down

edvwvw

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...excel/200806/1


Harald Staff[_2_]

Writing a UDF
 
Gentlemen, this is a question of symmetry and style,"don't have to" is not
an issue ;-)

Function GradeLetter(Grade as Integer) as String
Select case Grade
Case 1
GradeLetter = "H--"
Case 2
GradeLetter = "To be shot"
Case 3
GradeLetter = "Aww"

... and so on
Best wishes Harald


"Hajiki" wrote in message
...
I used this (see below) UDF successfully (can't believe it) but now I want
to
do te opposite where 15 =A+, no idea how to write it!

Function Grades(Letter As String) As Integer
Select Case Letter
Case Is = "A+"
Grades = 15
Case Is = "A"
Grades = 14
Case Is = "A-"
Grades = 13
Case Is = "B+"
Grades = 12
Case Is = "B"
Grades = 11
Case Is = "B-"
Grades = 10
Case Is = "C+"
Grades = 9
Case Is = "C"
Grades = 8
Case Is = "C-"
Grades = 7
Case Is = "D+"
Grades = 6
Case Is = "D"
Grades = 5
Case Is = "D-"
Grades = 4
Case Is = "F+"
Grades = 3
Case Is = "F"
Grades = 2
Case Is = "F-"
Grades = 1
End Select
End Function




All times are GMT +1. The time now is 11:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com