Option ExplicitDim rng As Range, fnd As Range
Dim Ctrl As Control
Dim iRow As Long, i As Long
Dim wsAE As Worksheet
Dim cell
Private Sub C_02_Click()
'Autofill Plant Number, Profit Center, and Purchasing Group
T_02.Value = C_02.Column(1)
T_12.Value = C_02.Column(3)
T_13.Value = C_02.Column(4)
End Sub
Private Sub C_04_Click()
'Autofill LOT SIZE
If C_04.Value = "VB" Then T_11.Value = "HB"
If C_04.Value <> "VB" Then T_11.Value = ""
End Sub
Private Sub CMB_AddNew_Click()
'Code for Submit Button
T_10.Value = C_03.Value & ";" & T_06.Value & ":" & T_05.Value & "," & T_07.Value & "," & T_09.Value
Set wsAE = Worksheets("ADD-EXTEND")
If MsgBox("Correct entry?", vbYesNo + vbQuestion, "Check the data!") = vbNo Then Exit Sub
iRow = wsAE.Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
wsAE.Cells(iRow, 1).Resize(, 30).Value = Array(T_id.Value, C_02.Value, T_02.Value, C_01.Value, T_04.Value, _
T_03.Value, T_12.Value, T_13.Value, C_05.Value, C_04.Value, T_11.Value, C_03.Value, T_06.Value, _
T_05.Value, T_07.Value, T_09.Value, T_10.Value, T_08.Value, T_26.Value, T_14.Value, T_15.Value, _
T_16.Value, C_06.Value, T_17.Value, C_07.Value, T_23.Value, T_24.Value, T_01.Value, "", T_25.Value)
'Columns.AutoFit
MsgBox "The new entry has been saved.", vbInformation, "Done"
For Each Ctrl In Controls
If TypeName(Ctrl) = "TextBox" Or TypeName(Ctrl) = "ComboBox" Then Ctrl.Value = ""
Next Ctrl
LB_01.ListIndex = -1
LB_01.TopIndex = 0
Call UserForm_Initialize
End Sub
Private Sub CMB_Change_Click()
'Code for Change Button
T_01 = Now
T_23 = Environ("Username")
T_10.Value = C_03.Value & ";" & T_06.Value & ":" & T_05.Value & "," & T_07.Value & "," & T_09.Value
Set wsAE = Worksheets("ADD-EXTEND")
Set rng = wsAE.Range("A2:A" & wsAE.Cells(Rows.Count, "A").End(xlUp).Row)
Set fnd = rng.Find(What:=T_id.Value, LookIn:=xlValues, Lookat:=xlWhole)
If LB_01.ListIndex = -1 Then
MsgBox "First choose a item in the list!", vbCritical, "Attention!"
Exit Sub
Else
If T_id = vbNullString Then
MsgBox "Customizing is not possible, no entries found", vbExclamation, "Attention!"
Exit Sub
ElseIf Not fnd Is Nothing Then
Application.EnableEvents = False
If MsgBox("Correct entry?", vbYesNo + vbQuestion, "Check the data!") = vbNo Then Exit Sub
wsAE.Cells(fnd.Row, "A").Resize(, 30).Value = Array(T_id.Value, C_02.Value, T_02.Value, C_01.Value, _
T_04.Value, T_03.Value, T_12.Value, T_13.Value, C_05.Value, C_04.Value, T_11.Value, C_03.Value, _
T_06.Value, T_05.Value, T_07.Value, T_09.Value, T_10.Value, T_08.Value, T_26.Value, T_14.Value, _
T_15.Value, T_16.Value, C_06.Value, T_17.Value, C_07.Value, T_23.Value, T_24.Value, T_01.Value, _
"", T_25.Value)
'Columns.AutoFit
MsgBox "The changes have been saved.", vbInformation, "Done"
Application.EnableEvents = True
End If
For Each Ctrl In Controls
If TypeName(Ctrl) = "TextBox" Or TypeName(Ctrl) = "ComboBox" Then Ctrl.Value = ""
Next Ctrl
LB_01.ListIndex = -1
LB_01.TopIndex = 0
Call UserForm_Initialize
End If
End Sub
Private Sub CMB_Clear_Click()
'Clear all fields
For Each Ctrl In Controls
If TypeName(Ctrl) = "TextBox" Or TypeName(Ctrl) = "ComboBox" Then Ctrl.Value = ""
Next Ctrl
LB_01.ListIndex = -1
LB_01.TopIndex = 0
Call UserForm_Initialize
End Sub
Private Sub CMB_Close_Click()
'Close the userform
Unload Me
End Sub
Private Sub LB_01_Click()
'List box column order
T_id.Value = LB_01.Column(0)
C_02.Value = LB_01.Column(1)
T_02.Value = LB_01.Column(2)
C_01.Value = LB_01.Column(3)
T_04.Value = LB_01.Column(4)
T_03.Value = LB_01.Column(5)
T_12.Value = LB_01.Column(6)
T_13.Value = LB_01.Column(7)
C_05.Value = LB_01.Column(8)
C_04.Value = LB_01.Column(9)
T_11.Value = LB_01.Column(10)
C_03.Value = LB_01.Column(11)
T_06.Value = LB_01.Column(12)
T_05.Value = LB_01.Column(13)
T_07.Value = LB_01.Column(14)
T_09.Value = LB_01.Column(15)
T_10.Value = LB_01.Column(16)
T_08.Value = LB_01.Column(17)
T_26.Value = LB_01.Column(18)
T_14.Value = LB_01.Column(19)
T_15.Value = LB_01.Column(20)
T_16.Value = LB_01.Column(21)
C_06.Value = LB_01.Column(22)
T_17.Value = LB_01.Column(23)
C_07.Value = LB_01.Column(24)
T_23.Value = LB_01.Column(25)
T_24.Value = LB_01.Column(26)
T_01.Value = LB_01.Column(27)
T_25.Value = LB_01.Column(29)
End Sub
Private Sub UserForm_Initialize()
'Textbox and Combobox values
T_id.Value = WorksheetFunction.Max([ids]) + 1
LB_01.List = [database].Value
C_01.List = [Action].Value
C_02.List = [datalist].Value
C_03.List = [nouns].Value
C_04.List = [mrp].Value
C_05.List = [BUoM].Value
C_06.List = [matgroup].Value
C_07.List = [bom].Value
T_01.Value = Now
T_23.Value = Environ("Username")
End Sub
Private Sub CMB_Approve_Click()
Dim approveName As String
T_24.Value = Environ("Username")
approveName = T_24.Value
Select Case approveName
Case "Robert.Conklin", "Bill.Howell", "Tracy.Corbitt", "Danny.Crosby", "Mike.Dees", "Billy.Howell", _
"Tony.Thompson", "Ron.Lee", "Jerry.Hubbard", "Darrel.Funderburk", "Jason.Moseley", "Radley.Scott", _
"Vassel.Spencer", "Earl.Howell", "Anthony.Mack", "Jim.West", "Jeremy.Wilt", "Kenneth.Redd", _
"Graham.Brown", "Domingo.Malave", "Mike.Wester", "Howard.Hendon", "Steve.Barnes", "Troy.Thomas", _
"Euney.Fontenot", "Paul.Brown", "Darvis.Trahan", "Raul.Garcia", "John.Kocian", "Matt.Doris", "Mike.Kirk", _
"Richard.Stone", "Steve.King", "Stephan.Grigg", "Robert.Cooper", "Chris.Stewart", "Don.Ziegler", _
"Jon.Knoop", "Rick.Kocurek", "Brian.Rutecki", "Kenny.Johnson", "Kenyon.Baker", "Gerald.Burt", _
"Victor.Aldana", "Billy.Reese", "Mike.Nagel", "Andy.Kelly", "Mike.Sulzbach", "Patrick.Dashnaw", _
"Carl.McMahan", "Rob.Clamp", "Alan.Wilson", "Robert.Faulk", "Armand.Kelle", "Victor.Romero", "Cain.Soto", _
"Mike.Huston", "Tom.Raggousis", "Keith.Palmer", "Monty.Wood", "Henry.Staley", "Rick.Dubois", _
"Harold.Wyman", "Steve.Bly", "Tom.Ladd", "Bill.Morrow", "Ron.Porter", "Joseph.Richard", "Angel.Sanchez", _
"Jaime.Santacruz", "John.Luck", "John.Uzell", "Doug.Meyer", "Ray.Taylor", "Tommy.Garrett", _
"Chad.Harland", "Scott.Pate", "Paul.LaFond", "Chuck.Harrity", "Tim.DuBose", "Rick.Stolarik", "Dan.Bader", _
"Johnny.Oliver", "Jeff.Daugherty", "Jerry.Lambert", "Justin.Smith", "David.Seay", "David.Phillips", _
"Brad.Akers", "Matt.Fountain", "Joe.Hicks", "Wesley.Knapp", "Joey.Bovona", "Colt.Burris", "John.Pacheco", _
"Frank.Palmer", "Ronnie.Kilgore", "Dana.Taylor", "Tom.Hundley", "Dorman.Karr", "Paul.Staats", _
"Steve.Johnson", "Ricky.Dixon", "Les.Parrish", "Terry.Simmons", "Chad.Metevier", "Ciro.Garcia", _
"Steve.Nichols", "Danny.Bennett", "Randy.Johnson"
If MsgBox("Hey " & T_24.Value & " are you sure you want to approve all?", vbYesNo + vbQuestion, "Sure!") = vbNo Then Exit Sub
Set rng = [ids]
For Each cell In rng
If cell.Value <> "" Then
cell.Offset(0, 26).Value = T_24.Value
cell.Offset(0, 28).Value = Now
End If
Next
MsgBox "Approved!", vbInformation, "Done."
Case Else
MsgBox "You Do Not Have Authorization To Approve This!", vbCritical, "Attention"
T_24.Value = ""
End Select
End Sub