Solved

Duplicate message

Posted on 2013-11-26
3
231 Views
Last Modified: 2013-11-26
Hello,
When entering data in the Parts fields (PartBox1). Is it possible if anything in colum B16:B300 entered that when you click on the submit button that a error will message If a duplicate part number entry is not allowed close or resubmit a new part number. I attached the excel doc.
DATA-Q28275571-1-.xlsm
0
Comment
Question by:HEMIChallenger
3 Comments
 
LVL 6

Expert Comment

by:zipa72
ID: 39679127
Hi HEMIChallenger,

In the CommandButton1_Click (SUBMIT button code) first check if there is a value in your PART column, and then do the appropriate action. I would simply show a message and focus the PartBox1, without even leaving the form.
0
 
LVL 18

Accepted Solution

by:
Steven Harris earned 500 total points
ID: 39679144
You may want to try adding something along the lines of:

Private Sub CommandButton1_Click()
'Check if Part Number is unique
Dim cell As Range
Dim errorcheck As Boolean
Dim answer As String
answer = UserForm1.PartBox1.Value

For Each cell In Range("B16:B300")
    If cell = answer Then errorcheck = True
Next cell

If errorcheck = True Then
    MsgBox "Duplicate Part numbers are not allowed.  Please try again."
Else
       'your code here
End If
End Sub

Open in new window


This should give you something similar to:

Private Sub CommandButton1_Click()
Dim nextrow As Integer

'Check PartBox1 is unique
Dim cell As Range
Dim errorcheck As Boolean
Dim answer As String
answer = UserForm1.PartBox1.Value

For Each cell In Range("B16:B300")
    If cell = answer Then errorcheck = True
Next cell

If errorcheck = True Then
    MsgBox "Duplicate Part numbers are not allowed.  Please try again."
Else
       
'=COUNTA(A:A)+1
nextrow = WorksheetFunction.CountA(Sheets(Range("F2").Value).Range("A:A")) + 1

Sheets(Range("F2").Value).Cells(nextrow + 14, 1) = Date
Sheets(Range("F2").Value).Cells(nextrow + 14, 2) = answer
Sheets(Range("F2").Value).Cells(nextrow + 14, 3) = UserForm1.BuildingBox2.Value
Sheets(Range("F2").Value).Cells(nextrow + 14, 4) = UserForm1.NameBox1.Value
Sheets(Range("F2").Value).Cells(nextrow + 14, 7) = UserForm1.EmployeeBox4.Value
End If
End Sub

Open in new window

0
 

Author Closing Comment

by:HEMIChallenger
ID: 39679720
That works perfect. Thank you.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to read all the sheets in excel 12 44
Hiding column macro 10 28
Excel printing page management 2 25
How do I crate a Pivot table in Excel 2 11
This article will show you how to use shortcut menus in the Access run-time environment.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now