Private Sub CommandButton1_Click()
Dim area1 As Variant
Dim area2 As Variant
Dim i As Long
Dim i2 As Long
Dim rngTxt1 As Range
Dim rngTxt2 As Range
Dim valTxt1 As String
Dim valTxt2 As String
Dim sameRow As Long
If Me.ComboBox2.Value = "" Then
MsgBox "Please choose a shift.", vbExclamation, "s"
Me.ComboBox2.SetFocus
Exit Sub
End If
If Me.ComboBox1.Value = "" Then
MsgBox "Please choose a SKU.", vbExclamation, "s"
Me.ComboBox1.SetFocus
Exit Sub
End If
Range("C12").Select
area1 = Array("C12", "D12", "F12", "H12", "J12", "L12", "N12", "P12", "R12", "T12", "V12", "X12", "C27", "D27", "F27", "H27", "J27", "L27", "N27", "P27", "R27", "T27", "V27", "X27")
On Error Resume Next
For i = LBound(area1) To UBound(area1)
If ActiveCell.Value = "" Then Exit For
If i = UBound(area1) Then
MsgBox "The sheet is full please start a new page"
Exit Sub
Else
Range(area1(i + 1)).Select
End If
Next i
ActiveCell = Me.ComboBox1.Value
ActiveCell.Offset(1, 0).Select
ActiveCell = Me.ComboBox2.Value
ActiveCell.Offset(1, 0).Select
ActiveCell = VBA.Format(Now(), "HH:MM")
ActiveCell.Offset(1, 0).Select
ActiveCell = ((Me.TextBox2.Value - Me.TextBox18.Value) - Me.TextBox1.Value)
ActiveCell.Offset(1, 0).Select
ActiveCell = ((Me.TextBox3.Value - Me.TextBox18.Value) - Me.TextBox1.Value)
ActiveCell.Offset(1, 0).Select
ActiveCell = ((Me.TextBox4.Value - Me.TextBox18.Value) - Me.TextBox1.Value)
ActiveCell.Offset(1, 0).Select
ActiveCell = ((Me.TextBox5.Value - Me.TextBox18.Value) - Me.TextBox1.Value)
ActiveCell.Offset(1, 0).Select
ActiveCell = ((Me.TextBox6.Value - Me.TextBox18.Value) - Me.TextBox1.Value)
ActiveCell.Offset(1, 0).Select
ActiveCell = ((Me.TextBox2.Value - Me.TextBox18.Value) - Me.TextBox1.Value) + ((Me.TextBox3.Value - Me.TextBox18.Value) - Me.TextBox1.Value) + ((Me.TextBox4.Value - Me.TextBox18.Value) - Me.TextBox1.Value) + ((Me.TextBox5.Value - Me.TextBox18.Value) - Me.TextBox1.Value) + ((Me.TextBox6.Value - Me.TextBox18.Value) - Me.TextBox1.Value)
ActiveCell.Offset(1, 0).Select
ActiveCell = (((Me.TextBox2.Value - Me.TextBox18.Value) - Me.TextBox1.Value) + ((Me.TextBox3.Value - TextBox18.Value) - Me.TextBox1.Value) + ((Me.TextBox4.Value - Me.TextBox18.Value) - Me.TextBox1.Value) + ((Me.TextBox5.Value - Me.TextBox18.Value) - Me.TextBox1.Value) + ((Me.TextBox6.Value - Me.TextBox18.Value) - Me.TextBox1.Value)) / Application.Count(Me.TextBox2.Value, Me.TextBox3.Value, Me.TextBox4.Value, Me.TextBox5.Value, Me.TextBox6.Value)
ActiveCell.Offset(1, 0).Select
ActiveCell = Me.TextBox1.Value
ActiveCell.Offset(1, 0).Select
ActiveCell = Me.TextBox9.Value
ActiveCell.Offset(1, 0).Select
ActiveCell = Me.TextBox8.Value
ActiveCell.Offset(-14, 0).Select
ActiveCell = Me.TextBox25.Value
Me.TextBox2.Value = ""
Me.TextBox10.Value = ""
Me.TextBox3.Value = ""
Me.TextBox11.Value = ""
Me.TextBox4.Value = ""
Me.TextBox12.Value = ""
Me.TextBox5.Value = ""
Me.TextBox13.Value = ""
Me.TextBox6.Value = ""
Me.TextBox14.Value = ""
Me.TextBox8.Value = ""
Me.TextBox19.Value = ""
Me.TextBox20.Value = ""
Me.TextBox21.Value = ""
Me.TextBox22.Value = ""
Me.TextBox23.Value = ""
Me.TextBox24.Value = ""
Me.TextBox25.Value = ""
ActiveCell.Offset(2, 1).Select
Me.TextBox8.SetFocus
If Me.TextBox26.Value <> "" Then
Set rngTxt1 = Range("G3:G5")
Set rngTxt2 = Range("H3:H5")
valTxt1 = Me.ComboBox2.Value
valTxt2 = Me.ComboBox1.Value
sameRow = findMatchRow(valTxt1, valTxt2, rngTxt1, rngTxt2)
'// -1 is the rows do not match or values not found return value
If sameRow <> -1 Then
Range("AJ" & sameRow).Select
ActiveCell = Me.TextBox26.Text
ActiveCell.Offset(0, -1).Select
ActiveCell = Me.ComboBox3.Value
ActiveCell.Offset(0, -1).Select
ActiveCell = Format(Now(), "HH:MM")
End If
Me.TextBox26.Value = ""
Me.ComboBox3.Value = ""
Me.TextBox8.SetFocus
End If
ActiveWorkbook.Save
End Sub