whiskey_kind_of_night
New Member
- Joined
- Aug 18, 2021
- Messages
- 2
- Office Version
- 2016
- Platform
- Windows
Hello forum, This is my first time using VBA. I'm attempting to make a data entry form to input trainings.
My goal is to select multiple names in order to create multiple entries with the same training information.
At the moment my form looks like this, where I choose the employee name one at a time and hit submit, which produces the data on a table. I have it so that each time it submits, only the "employee" section resets and I can quickly choose another name and submit again.
I'm trying to figure out how to change the ComboBox to a multiselect ListBox that will produce multiple entries on one table. I would also like to be able to pull the names from a specific column on a separate sheet instead of having the names as part of the code as I do now. Is this possible?
My current code is as follows
Thank you in advance!
My goal is to select multiple names in order to create multiple entries with the same training information.
At the moment my form looks like this, where I choose the employee name one at a time and hit submit, which produces the data on a table. I have it so that each time it submits, only the "employee" section resets and I can quickly choose another name and submit again.
I'm trying to figure out how to change the ComboBox to a multiselect ListBox that will produce multiple entries on one table. I would also like to be able to pull the names from a specific column on a separate sheet instead of having the names as part of the code as I do now. Is this possible?
My current code is as follows
VBA Code:
Private Sub CommandButton1_Click()
''''''''''' Validation '''''''''''''
If Me.OptionButton1.Value = False And Me.OptionButton2.Value = False And Me.OptionButton3.Value = False Then
MsgBox "Please select completed option", vbCritical
Exit Sub
End If
If Me.ComboBox1.Value = "" Then
MsgBox "Please select an employee.", vbCritical
Exit Sub
End If
If VBA.IsDate(Me.TextBox3.Value) = False Then
MsgBox "Please enter a date", vbCritical
Exit Sub
End If
''''''''''''''''''''
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Data")
Dim n As Long
_____________
'''''''''''''''''' Enter the date
n = sh.Range("C" & Application.Rows.Count).End(xlUp).Row
sh.Range("D" & n + 1).Value = Me.TextBox1.Value
sh.Range("E" & n + 1).Value = Me.TextBox2.Value
'Completed
If Me.OptionButton1.Value = True Then
sh.Range("I" & n + 1).Value = "Yes"
End If
If Me.OptionButton2.Value = True Then
sh.Range("I" & n + 1).Value = "No"
End If
If Me.OptionButton3.Value = True Then
sh.Range("I" & n + 1).Value = "Not Required"
End If
'Type of Training
If Me.OptionButton4.Value = True Then
sh.Range("G" & n + 1).Value = "EHS"
End If
If Me.OptionButton6.Value = True Then
sh.Range("G" & n + 1).Value = "QMS"
End If
If Me.OptionButton5.Value = True Then
sh.Range("G" & n + 1).Value = "PPG"
End If
If Me.OptionButton7.Value = True Then
sh.Range("G" & n + 1).Value = "Other"
End If
sh.Range("C" & n + 1).Value = Me.ComboBox1.Value
sh.Range("H" & n + 1).Value = Me.TextBox3.Value
sh.Range("F" & n + 1).Value = Me.TextBox4.Value
'''''''''' Clear boxes
Me.ComboBox1.Value = ""
End Sub
____________
Private Sub CommandButton2_Click()
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.OptionButton1.Value = False
Me.OptionButton2.Value = False
Me.OptionButton3.Value = False
Me.OptionButton4.Value = False
Me.OptionButton5.Value = False
Me.OptionButton6.Value = False
Me.OptionButton7.Value = False
Me.ComboBox1.Value = ""
End Sub
__________
Private Sub UserForm_Activate()
With Me.ComboBox1
.Clear
.AddItem ""
'''''List of employee names added here
End With
End Sub
Thank you in advance!