More than 1 score

Plastik808

New Member
Joined
Aug 15, 2011
Messages
11
Hi Everyone...i am new to VBA and am stuck on a problem. I am trying to expand the following so i can have say 10 people having taken a test and require the code to tell me if they pass or fail. I have tried using score = Range("A1:A10").Value, but i got an error

Private Sub CommandButton1_Click()
Dim score As Integer, grade As String
score = Range("A1").Value
If score >= 60 Then
grade = "passed"
Else
grade = "failed"
End If
Range("B1").Value = grade
End Sub


Many thanks
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try this...

Code:
Private Sub CommandButton1_Click()
Dim grade(1 to 10) As String
Dim i as Integer
For i = 1 to 10
    grade(i) = IIF(Range("A" & i) >= 60, "passed", "failed")
Next i
End Sub

You might actually need to declare the grade array as a Public variable, so it is accessible in your Module.
 
Upvote 0
Welcome to the MrExcel board!

Do you really need a Command Button and code? Could you just use a worksheet formula like this, copied down?

Excel Workbook
AB
1ScoreGrade
28failed
395passed
4
560passed
6122passed
780passed
859.5failed
9
1066passed
Grade
 
Upvote 0
Try this...

Code:
Private Sub CommandButton1_Click()
Dim grade(1 to 10) As String
Dim i as Integer
For i = 1 to 10
    grade(i) = IIF(Range("A" & i) >= 60, "passed", "failed")
Next i
End Sub
Wouldn't you need to write the array values back to the sheet?
 
Upvote 0
Wouldn't you need to write the array values back to the sheet?

My bad :(

Code:
Private Sub CommandButton1_Click() 
Dim grade(1 to 10) As String 
Dim i as Integer 
    For i = 1 to 10     
        Range("B" & i) = IIF(Range("A" & i) >= 60, "passed", "failed")
    Next i 
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,520
Members
452,921
Latest member
BBQKING

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top