Private Sub CommandButton3_Click()
Dim ws As Worksheet
Dim MyForm As UserForm1
With Application
.Calculation = xlCalculationManual
.EnableEvents = False
.ScreenUpdating = False
End With
Set ws = Worksheets("FT Scores")
Set MyForm = UserForm1
With MyForm
'Message Boxes
If TextBox11.Value = TextBox12.Value Then
MsgBox "Oi Muppet, sort the teams out!"
Exit Sub
End If
If TextBox11.Value = "" Or TextBox12.Value = "" Or TextBox3.Value = "" _
Or TextBox4.Value = "" Or TextBox7.Value = "" Then
MsgBox "Oi Losers, sort the Team or Scores out!"
Exit Sub
End If
If TextBox1.Value > TextBox3.Value Or TextBox2.Value > TextBox4.Value Then
MsgBox "Incorrect Scores Muppet!"
Exit Sub
End If
End With
'find first empty row was here
'copy the data to the database
With ws
'find first empty row in database
lRow = ws.Cells(Rows.Count, 3) _
.End(xlUp).Offset(1, 0).Row
.Cells(lRow, 3).Value = Me.TextBox11.Value
.Cells(lRow, 5).Value = Me.TextBox1.Value
.Cells(lRow, 6).Value = Me.TextBox2.Value
.Cells(lRow, 4).Value = Me.TextBox12.Value
.Cells(lRow, 7).Value = Me.TextBox7.Value
.Cells(lRow, 8).Value = Me.TextBox3.Value
.Cells(lRow, 9).Value = Me.TextBox4.Value
End With
With MyForm
'clear the data
Me.TextBox11.Value = ""
Me.TextBox12.Value = ""
Me.SpinButton1.Value = "0"
Me.SpinButton2.Value = "0"
Me.SpinButton3.Value = "0"
Me.SpinButton4.Value = "0"
Me.TextBox7.Value = Format(Date, "Medium Date")
End With
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
With UserForm1.ListBox1
If (.Value <> vbNullString) Then
'If more then one data rows
If (.ListIndex >= 0 And Range("A12").End(xlUp) > 2) Then
Range("A" & .ListIndex + 1).Resize(1, 2).Delete Shift:=xlUp
.RowSource = "Results!A1:" & Range("B12").End(xlUp).Address
'If only one data row
ElseIf (.ListIndex = 0 And Range("A12").End(xlUp) = 1) Then
Range("A1").Resize(1, 2).Delete
'Update listbox
.RowSource = "Results!A2:B2"
End If
Else
MsgBox "Please Select Data"
End If
End With
End Sub