VBA for Userform to add data values

Strycure12

New Member
Joined
Dec 5, 2022
Messages
8
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
Hello,

I have currently a userform that has code for unloading to a sheet. ,have the code down and one issue I can't resolve is the having a user to select a combobox value, and then the user selects in adjacent text box a number value. After that been done then hold value and combobox term , while in same box select an other value and repeat same process.

I have tried multiple different integrations but cannot figure out how.

If some one can help it will be greatly appreciated.

Here is the code below 👇

Private Sub CommandButton1_Click()
Dim Tbl As ListObject
Dim NewRow As ListRow
Dim WhichColumn(1 To 12) As Long, BoxIndex(1 To 12) As Long


'Obtain combobox selection listindex
BoxIndex(1) = Me.ComboBox2.ListIndex + 1
If BoxIndex(1) < 1 Then BoxIndex(1) = 1

BoxIndex(2) = Me.ComboBox5.ListIndex + 1
If BoxIndex(2) < 1 Then BoxIndex(2) = 1

BoxIndex(3) = Me.ComboBox10.ListIndex + 1
If BoxIndex(3) < 1 Then BoxIndex(3) = 1

BoxIndex(4) = Me.ComboBox6.ListIndex + 1
If BoxIndex(4) < 1 Then BoxIndex(4) = 1

BoxIndex(5) = Me.ComboBox8.ListIndex + 1
If BoxIndex(5) < 1 Then BoxIndex(5) = 1

BoxIndex(6) = Me.ComboBox7.ListIndex + 1
If BoxIndex(6) < 1 Then BoxIndex(6) = 1

BoxIndex(7) = Me.ComboBox11.ListIndex + 1
If BoxIndex(7) < 1 Then BoxIndex(7) = 1

BoxIndex(8) = Me.ComboBox12.ListIndex + 1
If BoxIndex(8) < 1 Then BoxIndex(8) = 1

BoxIndex(9) = Me.ComboBox13.ListIndex + 1
If BoxIndex(9) < 1 Then BoxIndex(9) = 1

BoxIndex(10) = Me.ComboBox4.ListIndex + 1
If BoxIndex(10) < 1 Then BoxIndex(10) = 1

BoxIndex(11) = Me.ComboBox9.ListIndex + 1
If BoxIndex(11) < 1 Then BoxIndex(11) = 1

BoxIndex(12) = Me.ComboBox3.ListIndex + 1
If BoxIndex(12) < 1 Then BoxIndex(12) = 1

'set object variable
Set Tb1 = Worksheets("PLM LM EIA LOG DATA").ListObjects("Table1")

'Add New row to the table
Set NewRow = Tb1.ListRows.Add(AlwaysInsert:=True)

'get column in table to post value of textbox's to.
WhichColumn(1) = Tb1.ListColumns(Choose(BoxIndex(1), "Damage Clamp", "Clamp Incorrectly Installed", "Gapped Clamp")).Range.Column
WhichColumn(2) = Tb1.ListColumns(Choose(BoxIndex(2), "Gap Fill (Low/High/Void)", "Debris (Sealant Balls/Paint chips)")).Range.Column
WhichColumn(3) = Tb1.ListColumns(Choose(BoxIndex(3), "Frozen Nutplate", "Bent (Strap/Tube/Structure)", "Red Witness Line Visible (Harness Connector)", "Uninstalled Connector", "Connector Clocked Incorrectly", "Loose Fastener")).Range.Column
WhichColumn(4) = Tb1.ListColumns(Choose(BoxIndex(4), "Harness Fouling", "Loose Clamp", "String Tie", "Bend Radius", "Insufficient harness clearance", "Mis-Routed Wiring")).Range.Column
WhichColumn(5) = Tb1.ListColumns(Choose(BoxIndex(5), "FO (Off Product) (Not included in EIA VOC Per A/C Metrics)", "Low Form 1 ", "TMS Fan Raised Material", "Hair/Dust/String(Not included in EIA VOC Per A/C Metrics)", "Center Not Grounded ", "Missing torque stripe")).Range.Column
WhichColumn(6) = Tb1.ListColumns(Choose(BoxIndex(6), "Missing ID", "ID Label Under Clamp", "Missing/Peeling label")).Range.Column
WhichColumn(7) = Tb1.ListColumns(Choose(BoxIndex(7), "Sealant Void/Insufficent", "Sealant Re-entry", "Excessive Sealant", "Debris (Sealant Balls/Paint chips)", "Damaged Bulb Seal", "Unpromoted Seal ", "Adhesive on Seal Frame ", "Uncured Sealant (MU0008)", "Flex (Low/Missing/High) ")).Range.Column
WhichColumn(8) = Tb1.ListColumns(Choose(BoxIndex(8), "Missing Alodine")).Range.Column
WhichColumn(9) = Tb1.ListColumns(Choose(BoxIndex(9), "Tube Fouling", "Tube Clearance", "Hydro Leak", "Loose Clamp", "Crushed/Deformed Convoluted Tube", "Tube w/ID under clamp (acceptable if other ID is within 12 inches)")).Range.Column
WhichColumn(10) = Tb1.ListColumns(Choose(BoxIndex(10), "F.O.D")).Range.Column
WhichColumn(11) = Tb1.ListColumns(Choose(BoxIndex(11), "Drips", "Missing Paint/Flexprime", "Chipped Paint", "Bare Metal/Gouge")).Range.Column
WhichColumn(12) = Tb1.ListColumns(Choose(BoxIndex(12), "Bare Hole ID's")).Range.Column

'posts new record to table
With NewRow
.Range(1).Value = Me.TextBox14.Value
.Range(2).Value = Me.TextBox17.Value
.Range(3).Value = Me.ComboBox15.Value
.Range(4).Value = Me.ComboBox16.Value + ("-") + Me.TextBox16.Value

.Range(WhichColumn(1)).Value = Me.TextBox2.Value
.Range(WhichColumn(2)).Value = Me.TextBox5.Value
.Range(WhichColumn(3)).Value = Me.TextBox10.Value
.Range(WhichColumn(4)).Value = Me.TextBox6.Value
.Range(WhichColumn(5)).Value = Me.TextBox8.Value
.Range(WhichColumn(6)).Value = Me.TextBox7.Value
.Range(WhichColumn(7)).Value = Me.TextBox11.Value
.Range(WhichColumn(8)).Value = Me.TextBox12.Value
.Range(WhichColumn(9)).Value = Me.TextBox13.Value
.Range(WhichColumn(10)).Value = Me.TextBox4.Value
.Range(WhichColumn(11)).Value = Me.TextBox9.Value
.Range(WhichColumn(12)).Value = Me.TextBox3.Value

End With
Unload UserForm2

Private Sub UserForm_Initialize()
Dim ws As Worksheet
Set ws = Worksheets("PLM ")
Set Tb1 = Worksheets("PLM") DATA").ListObjects("Table1")

ComboBox18.RowSource = "=Table1[A]"

UserForm1.Hide

TextBox14.Value = Format(Date, "mm/dd/yyyy")


With ComboBox15

.AddItem "12:00:00 AM"
.AddItem "1:00:00 AM"
.AddItem "2:00:00 AM"
.AddItem "3:00:00 AM"
.AddItem "4:00:00 AM"
.AddItem "5:00:00 AM"
.AddItem "6:00:00 AM"
.AddItem "7:00:00 AM"
.AddItem "8:00:00 AM"
.AddItem "9:00:00 AM"
.AddItem "10:00:00 AM"
.AddItem "11:00:00 AM"
.AddItem "12:00:00 PM"
.AddItem "1:00:00 PM"
.AddItem "2:00:00 PM"
.AddItem "3:00:00 PM"
.AddItem "4:00:00 PM"
.AddItem "5:00:00 PM"
.AddItem "6:00:00 PM"
.AddItem "7:00:00 PM"
.AddItem "8:00:00 PM"
.AddItem "9:00:00 PM"
.AddItem "10:00:00 PM"
.AddItem "11:00:00 PM"
.AddItem "12:00:00 PM"

With ComboBox16
.
.AddItem "AF"
.AddItem "AK"
.AddItem "AL"
.AddItem "AM"
.AddItem "AN"
.AddItem "AP"
.AddItem "AQ"
.AddItem "AR"
.AddItem "AS"
.AddItem "AT"
.AddItem "AU"
.AddItem "AV"
.AddItem "AW"
.AddItem "AX"
.AddItem "AY"
.AddItem "BF"
.AddItem "BK"
.AddItem "BL"
.AddItem "BM"
.AddItem "BN"
.AddItem "BP"
.AddItem "BQ"
.AddItem "BR"
.AddItem "BS"
.AddItem "BT"
.AddItem "BU"
.AddItem "BV"
.AddItem "BW"
.AddItem "BX"
.AddItem ""
.AddItem "(CV)"
.AddItem "CF"
.AddItem "CK"
.AddItem "CL"
.AddItem "CM"
.AddItem "CN"
.AddItem "CP"
.AddItem "CQ"
.AddItem "CR"
.AddItem "CS"
.AddItem "CT"
.AddItem "CU"
.AddItem "CV"
.AddItem "CW"
.AddItem "CX"


With ComboBox2 'clamps
.AddItem "Clamp Incorrectly Installed"
.AddItem "Damage Clamp"
.AddItem "Gapped Clamp"


With ComboBox3 'Dimentional
.AddItem "Bare Hole ID's"

With ComboBox4 'FOD
.AddItem "F.O.D"

With ComboBox5 'GAP
.AddItem "Gap Fill (Low/High/Void)"
.AddItem "Debris"

With ComboBox6 'Harness
.AddItem "Harness Fouling"
.AddItem "Loose Clamp (Tube/Harness)"
.AddItem "String Tie"
.AddItem "Bend Radius"
.AddItem "Insufficient harness clearance"
.AddItem "Mis-Routed Wiring"

With ComboBox7 ' ID
.AddItem "Missing ID"
.AddItem "ID Label Under Clamp"
.AddItem "Missing/Peelinglabel"

With ComboBox8 'Misc
.AddItem "FO (Off Product) (Not included in EIA VOC Per A/C"
.AddItem "Low Form 1"
.AddItem "TMS Fan Raised Material"
.AddItem "Hair/Dust/String(Not included in EIA VOC Per A/C Metrics)"
.AddItem "Center Not Grounded"
.AddItem "Missing torque stripe"

With ComboBox9 'paint
.AddItem "Drips"
.AddItem "Missing Paint/Flexprime"
.AddItem "Chipped Paint"
.AddItem "Bare Metal / Gouge"

With ComboBox10 'Hardware
.AddItem "Frozen Nutplate"
.AddItem "Bent (Strap/Tube/Structure)"
.AddItem "Incorrect Hardware"
.AddItem "Red Witness Line Visible on Connectors"
.AddItem "Uninstalled Connector"
.AddItem "Connector Clocked Incorrectly"
.AddItem "Loose Fastener"
With ComboBox11 'sealant
.AddItem "Sealant Void/Insufficent"
.AddItem "Sealant Re-entry"
.AddItem "Excessive Sealant"
.AddItem "Debris (Sealant Balls/Paint chips)"
.AddItem "Damaged Bulb Seal"
.AddItem "Unpromoted Seal"
.AddItem "Adhesive on Seal Frame"
.AddItem "Uncured Sealant (MU0008)"
.AddItem "Flex (Low/Missing/High)"
End With

With ComboBox12 'Surface Finish
.AddItem "Missing Alodine"
End With

With ComboBox13 'Tubing
.AddItem "Tube Fouling"
.AddItem "Tube Clearance"
.AddItem "Hydro Leak"
.AddItem "Loose Clamp"
.AddItem "Crushed/Deformed Convoluted Tube"
.AddItem "Tube w/ID under clamp (acceptable if other ID is within 12 inches)"
End With



End With
End With
End With
End With
End With
End With
End With
End With
End With
End With
End With




End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,224,820
Messages
6,181,157
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top