I created a userform and the code below attached to it. The userform consists of a text box, a combo box and the OK button. The code inserts a new job title (coming from the text box) at the end of a corresponding list based upon the users combobox selection - which then returns the corresponding job code (from the column to the left of the list) to a cell at the top of the spreadsheet.
I am pretty new to vba and am struggling to figure out how to prevent a duplicate entry within the separate lists. If the user enters a duplicate, I'm wanting it to return the original entries corresponding job code and prevent the entry from being added to the list.
I appreciate any ideas you may have!
I am pretty new to vba and am struggling to figure out how to prevent a duplicate entry within the separate lists. If the user enters a duplicate, I'm wanting it to return the original entries corresponding job code and prevent the entry from being added to the list.
I appreciate any ideas you may have!
Code:
Private Sub OK_Click()
If TextBox1 = vbNullString Then
MsgBox "You Must Enter A Job Name"
If vbOK Then
Me.TextBox1.SetFocus
Cancel = True
Exit Sub
End If
End If
If CreateJobCode = ("KC") Then
Range("D3").Value = (Range("B7:B65536").SpecialCells(4)(1, 0))
Range("B7:B65536").SpecialCells(4)(1).Select
Selection.Value = TextBox1
Unload Me
ElseIf CreateJobCode = ("KCPM") Then
Range("D3").Value = (Range("D7:D65536").SpecialCells(4)(1, 0))
Range("D7:D65536").SpecialCells(4)(1).Select
Selection.Value = TextBox1
Unload Me
ElseIf CreateJobCode = ("NEO") Then
Range("D3").Value = (Range("F7:F65536").SpecialCells(4)(1, 0))
Range("F7:F65536").SpecialCells(4)(1).Select
Selection.Value = TextBox1
Unload Me
ElseIf CreateJobCode = ("NEOPM") Then
Range("D3").Value = (Range("H7:H65536").SpecialCells(4)(1, 0))
Range("H7:H65536").SpecialCells(4)(1).Select
Selection.Value = TextBox1
Unload Me
ElseIf CreateJobCode = ("Non-Employee") Then
Range("D3").Value = (Range("J7:J65536").SpecialCells(4)(1, 0))
Range("J7:J65536").SpecialCells(4)(1).Select
Selection.Value = TextBox1
Unload Me
Else
MsgBox "Please Select An Option"
If vbOK Then
Me.CreateJobCode.SetFocus
End If
End If
Range("D3").Select
End Sub