Associate
- Joined
- 31 Dec 2002
- Posts
- 458
Hi,
I am just starting with vba in Excel 2010 and have done some .net Visual Basic programming. However I am finding it hard going with vba. I am trying to run the following, but keep getting errors when trying to run. My worksheet is called model and is the first sheet in the workbook:
Sub workoutgrade()
Dim grade As String
If Range("pass4") > 7 And Range("pass5") > 7 Then
grade = "Pass"
ElseIf Range("merit4") > 4 And Range("merit5") > 5 Then
grade = "Merit"
ElseIf Range("dist4") > 4 And Range("dist5") > 5 Then
grade = "Distinction"
ElseIf Range("pass4") + Range("pass5") < 16 And grade <> "Merit" Or "Distinction" Then
grade = "Fail"
Else: grade = "Merit"
Range("grade") = grade
End If
End Sub
the cells referred to by range hold a numerical value. I want to run the conditional tests and output the grade string to named range cell grade. Any ideas would be appreciated. I think I have probably got the syntax wrong!!!!
I am just starting with vba in Excel 2010 and have done some .net Visual Basic programming. However I am finding it hard going with vba. I am trying to run the following, but keep getting errors when trying to run. My worksheet is called model and is the first sheet in the workbook:
Sub workoutgrade()
Dim grade As String
If Range("pass4") > 7 And Range("pass5") > 7 Then
grade = "Pass"
ElseIf Range("merit4") > 4 And Range("merit5") > 5 Then
grade = "Merit"
ElseIf Range("dist4") > 4 And Range("dist5") > 5 Then
grade = "Distinction"
ElseIf Range("pass4") + Range("pass5") < 16 And grade <> "Merit" Or "Distinction" Then
grade = "Fail"
Else: grade = "Merit"
Range("grade") = grade
End If
End Sub
the cells referred to by range hold a numerical value. I want to run the conditional tests and output the grade string to named range cell grade. Any ideas would be appreciated. I think I have probably got the syntax wrong!!!!