Hello all. Please go easy on me. I do not use VBA very often however I do manage to put together some code for userforms based on forum topics I find. I use the code below to automatically transfer data from my userform to an excel worksheet. The code works great. Now I would like to update the code so that we do not have to fill out the userform for each PART of the job. For Example: A job can have more than one part, that is why I have the PartNumberBox and PartNumberOfBox. The user can select Part 1 of Part 3 which represents the first part of a 3 part job. With the current code I need to fill out the userform 3 times to get Part 1 of 3, Part 2 of 3 and Part 3 of 3. My question is, can I update this code so that when the user selects an option that has more than one part the code will automatically transfer the data X number of times (where X is the PartNumberOfBox). Hopefully this makes sense. Thanks so much.
Private Sub CreateJobNumber_Click()
Dim LastRow As Object
Dim MyMessage As String
Set LastRow = Sheets("Datasheet").Range("a65536").End(xlUp)
LastRow.Offset(1, 1).Value = UniqueCodeBox.Text
LastRow.Offset(1, 2).Value = RunCodeBox.Text
LastRow.Offset(1, 3).Value = RunNumberBox.Text
LastRow.Offset(1, 4).Value = PartNumberBox.Text
LastRow.Offset(1, 5).Value = PartNumberOfBox.Text
LastRow.Offset(1, 6).Value = InputCustomerName.Text
LastRow.Offset(1, 7).Value = InputJobName.Text
LastRow.Offset(1, 8).Value = InputCustomerJob.Text
LastRow.Offset(1, 9).Value = InputCustomerPO.Text
LastRow.Offset(1, 10).Value = InputQuantityOrdered.Text
LastRow.Offset(1, 11).Value = InputRunDate.Text
MsgBox "One record written to Sheets(Datasheet)"
MsgBox "Here is your Unique Code, please take a note for future reference."
MyMessage = "H" & Me.UniqueCodeBox.Text & "" & Me.RunNumberBox.Value & "" & Me.RunCodeBox.Value & "." & Me.PartNumberBox.Value & "." & Me.PartNumberOfBox.Value
MsgBox MyMessage
response = MsgBox("Do you want to enter another NEW JOB record?", _
vbYesNo)
If response = vbYes Then
UniqueCodeBox.Text = ""
RunCodeBox.Text = ""
RunNumberBox.Text = ""
PartNumberBox.Text = ""
PartNumberOfBox.Text = ""
InputCustomerName.Text = ""
InputJobName.Text = ""
InputCustomerJob.Text = ""
InputCustomerPO.Text = ""
InputQuantityOrdered.Text = ""
InputRunDate.Text = ""
Else
Unload UserForm2
End If
End Sub
Bookmarks