Hello All,
I am trying to make a fail-safe to avoid entering the wrong data in the worksheet. I will explain my Excel File (Attached) first.
Sheet1 - "Scanned Data" -> Has 3 columns: A = Ship From, B = Serial Number, C = Part Number
Sheet2 - "master Data" -> Has 3 columns: A = Ship From, B = Supplier Name, C = Part Number
In "Scanned Data", I have created a User-Form to take input for A = Ship From = TextBox1, B = Serial Number = TextBox2, C = Part Number = TextBox3.
AIM - Before entering the value in sheet 1 - the latest empty row, I want to make sure that the part number falls under the correct ship from (Supplier). This data is already present in Sheet2. Currently, I used the following logic for this purpose. But I think that logic is flawed and not in proper syntax.
Sub Compare_Data()
For i = 1 To EmptyRow
If TextBox1.Value = Worksheets("Sheet2").Cells(i, 1).Value And TextBox3.Value = Worksheets("Sheet2").Cells(i, 3).Value Then
GoTo Line2
Else
MsgBox "Scanned Part Does Not Match Supplier. Scan Correct Part Number"
TextBox3.SetFocus
End If
Next i
Line2:
End Sub
In "Master Data" you can see that for the same supplier(Ship From) I have multiple products and hence I don't know how to frame this logic. You can check the current programing in my sample file, and I am ready to provide more clarification if needed.
Would using Index and match be better? If so how to frame it.
Thanking you in Advance.
Bookmarks