When I execute my code on my user form, it sometimes shows the result and other times it doesn't.
What could be causing that problem?
Like, when I hit execute it'll give me an output, if I do it again with the same parameters it won't.
I don't know what's going on.
Any and all help is appreciated.
Thank you in advanced.
Here is a dropbox with my excel sheet:
Here is my code:
Private Sub CommandButton2_Click() Me.Hide End Sub
Private Sub excecute_button_Click()
'Declaring objects
Dim N As Long, i As Long, subjectCount As Long
Dim tmp_avg As Double
Dim student As Range
Dim reading As Range, writing As Range, grammar As Range, spelling As Range
Dim math As Range, science As Range, social As Range
Dim average As Range
Dim info As Worksheet
Dim cutoff As String
Dim cutoff_score As Double
Dim output As String
'Setting objects
Set info = Worksheets("Info")
Set student = Range(info.Cells(6, 3), info.Cells(55, 3))
Set reading = Range(info.Cells(6, 5), info.Cells(55, 5))
Set writing = Range(info.Cells(6, 6), info.Cells(55, 6))
Set grammar = Range(info.Cells(6, 7), info.Cells(55, 7))
Set spelling = Range(info.Cells(6, 8), info.Cells(55, 8))
Set math = Range(info.Cells(6, 9), info.Cells(55, 9))
Set science = Range(info.Cells(6, 10), info.Cells(55, 10))
Set social = Range(info.Cells(6, 11), info.Cells(55, 11))
Set average = Range(info.Cells(6, 13), info.Cells(55, 13))
'Counting subjects
subjectCount = Me.readingBox.Value + _
Me.writingBox.Value + _
Me.grammarBox.Value + _
Me.spellingBox.Value + _
Me.mathBox.Value + _
Me.scienceBox.Value + _
Me.socialBox.Value
'Reading cut-off cutoff = Me.cutoff_box.Value
N = Worksheets("Info").Range("S19").Value i = 1
Do While i < N
'Computing average
tmp_avg = (reading.Cells(i, 1) * Me.readingBox.Value + _
writing.Cells(i, 1) * Me.writingBox.Value + _
grammar.Cells(i, 1) * Me.grammarBox.Value + _
spelling.Cells(i, 1) * Me.spellingBox.Value + _
math.Cells(i, 1) * Me.mathBox.Value + _
science.Cells(i, 1) * Me.scienceBox.Value + _
social.Cells(i, 1) * Me.socialBox.Value) / subjectCount
'Rounding
If Me.Round.Value = True Then
average.Cells(i, 1).Value = WorksheetFunction.Ceiling(tmp_avg, 0.01)
Else
average.Cells(i, 1).Value = tmp_avg
End If
i = i + 1
'Checking whether student met honor roll requirements
Select Case cutoff
Case "A+"
cutoff_score = 0.96
Case "A"
cutoff_score = 0.93
Case "A-"
cutoff_score = 0.9
Case "B+"
cutoff_score = 0.86
Case "B"
cutoff_score = 0.83
Case "B-"
cutoff_score = 0.8
Case "C+"
cutoff_score = 0.76
Case "C"
cutoff_score = 0.73
Case "C-"
cutoff_score = 0.7
End Select
If average.Cells(i, 1).Value >= cutoff_score Then
output = output & student.Cells(i, 1).Value & " "
End If
Loop
MsgBox "HONOR ROLL" & vbNewLine & output
End Sub
Private Sub UserForm_Click()
End Sub
Show Button Code:
Sub honor_roll_button()
With honor_roll_form
'Loading combo box
.cutoff_box.Clear
.cutoff_box.AddItem "A+"
.cutoff_box.AddItem "A"
.cutoff_box.AddItem "A-"
.cutoff_box.AddItem "B+"
.cutoff_box.AddItem "B"
.cutoff_box.AddItem "B-"
.cutoff_box.AddItem "C+"
.cutoff_box.AddItem "C"
.cutoff_box.AddItem "C-"
.cutoff_box.Value = "B+"
'Setting default check boxes
honor_roll_form.readingBox = True
honor_roll_form.writingBox = True
honor_roll_form.grammarBox = True
honor_roll_form.spellingBox = True
honor_roll_form.mathBox = True
honor_roll_form.scienceBox = True
honor_roll_form.socialBox = True
honor_roll_form.Round = True
'Showing Form
.Show
End With
End Sub
Sub test()
Dim x As String
x = "hello"
x = x & vbNewLine & "goodbye"
MsgBox x
End Sub
cutoff = Me.cutoff_box.ValueandN = Worksheets("Info").Range("S19").Value i = 1)