Coding in vb editor in excel

Coding in vb editor

Now that we have set up the editor its time to do some coding inorder to have a user defined function. The user defined functions can be simple pieces of code to complex pieces of  code.



Caution Macro enabled files may contain viruses and should not be downloaded and used without scanning properly. We can now add a function that will do some work in our editor

So with our editor open paste the following code

Function marksgrade(C)
If C >= 91.5 And C <= 100 Then
marksgrade = “A”
ElseIf C >= 82.5 And C <= 91 Then
marksgrade = “A-“
ElseIf C >= 74.5 And C <= 82 Then
marksgrade = “B+”
ElseIf C >= 66.5 And C <= 74 Then
marksgrade = “B”
ElseIf C >= 59.5 And C <= 66 Then
marksgrade = “B-“
ElseIf C >= 51.5 And C <= 59 Then
marksgrade = “C+”
ElseIf C >= 44.5 And C <= 51 Then
marksgrade = “C”
ElseIf C >= 36.5 And C <= 44 Then
marksgrade = “C-“
ElseIf C >= 29.5 And C <= 36 Then
marksgrade = “D+”
ElseIf C >= 22.5 And C <= 29 Then
marksgrade = “D”
ElseIf C >= 15.5 And C <= 22 Then
marksgrade = “D-“
ElseIf C > 0 And C <= 15 Then
marksgrade = “E”
Else
marksgrade = “”

End If
End Function

This is a simple function to grade marks for students




Note the name of the function is marksgrade

Which requires argument C which is in brackets

Save your work

vbeditor1

More on functions you may read the tutorials on visual basic 2010 at VISUAL BASIC 2010

HOW TO USE OUR NEW FUNCTION

We have created a new function

The function assigns a grade to any mark passed to it

you can download the excel file from the link below

Excel file

so where we want our grade placed type = followed by our function name and select the cell where marks are

vbeditor2

 

then press enter.

vbeditor3

The grade appears

NOTE THAT YOU CAN NOW AUTO FILL IN THE OTHER CELLS