Dalricsin8
New Member
- Joined
- May 5, 2016
- Messages
- 4
Hello,
I would really appreciate any help that can be given. I have created a userform where I can track missed scan labels from my production team. I have 6 text boxes per ticket I need to fill in the userform. (all for different tracking purposes) What I need the userform to do is only check that two of the texts boxes are not a complete match to another entry when I hit enter. I attempted it and with a countifs but and I don't get error but it still enters duplicates. The columns I need to check are B and D. I am not very experienced so the code may be sloppy. Thank you for taking a look and if you need any more info please let me know.
I would really appreciate any help that can be given. I have created a userform where I can track missed scan labels from my production team. I have 6 text boxes per ticket I need to fill in the userform. (all for different tracking purposes) What I need the userform to do is only check that two of the texts boxes are not a complete match to another entry when I hit enter. I attempted it and with a countifs but and I don't get error but it still enters duplicates. The columns I need to check are B and D. I am not very experienced so the code may be sloppy. Thank you for taking a look and if you need any more info please let me know.
Code:
Private Sub Enter_Click()
Dim emptyRow As Long
Sheets(1).Activate
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
If Len(MissedScanLabelsReportUserform.fsap.Value) = 0 Then
MsgBox "SAP Number was left blank.", vbOKOnly, "Error"
MissedScanLabelsReportUserform.fsap.SetFocus
Exit Sub
End If
If Len(MissedScanLabelsReportUserform.forder.Value) = 0 Then
MsgBox "Production Order was left blank.", vbOKOnly, "Error"
MissedScanLabelsReportUserform.forder.SetFocus
Exit Sub
End If
If Len(MissedScanLabelsReportUserform.fqty.Value) = 0 Then
MsgBox "Quantity was left blank.", vbOKOnly, "Error"
MissedScanLabelsReportUserform.fqty.SetFocus
Exit Sub
End If
If Len(MissedScanLabelsReportUserform.fplt.Value) = 0 Then
MsgBox "Pallet Nummber was left blank.", vbOKOnly, "Error"
MissedScanLabelsReportUserform.fqty.SetFocus
Exit Sub
End If
If Len(MissedScanLabelsReportUserform.fshift.Value) = 0 Then
MsgBox "The Shift was left blank.", vbOKOnly, "Error"
MissedScanLabelsReportUserform.fqty.SetFocus
Exit Sub
End If
If Len(MissedScanLabelsReportUserform.fdate.Value) = 0 Then
MsgBox "The Date was left blank.", vbOKOnly, "Error"
MissedScanLabelsReportUserform.fqty.SetFocus
Exit Sub
End If
If Application.WorksheetFunction.CountIfs(Sheets(1).Range("B:B"), forder.Value > 0, Sheets(1).Range("D:D"), fplt.Value > 0) Then
MsgBox ("Already exists in the database; cannot be entered again")
Exit Sub
Else
Sheets(1).Cells(emptyRow, 1).Value = fsap.Value
Sheets(1).Cells(emptyRow, 2).Value = forder.Value
Sheets(1).Cells(emptyRow, 3).Value = fqty.Value
Sheets(1).Cells(emptyRow, 4).Value = fplt.Value
Sheets(1).Cells(emptyRow, 5).Value = fshift.Value
Sheets(1).Cells(emptyRow, 6).Value = fdate.Value
End If
Call UserForm_Initialize
End Sub