Multiple Records (Rows) from 1 Text Box, Userform

bugelboy93

New Member
Joined
Jan 17, 2006
Messages
16
I have a userform for data entry which populates a worksheet:

txtTrackingNumber
txtDate
txtName (should this even be a text box?)

I want Name to be able to accept one or more values and give me as many rows as there are values in Name, with the Tracking Number and Date being duplicated in each row.

e.g. what I enter:

Tracking Number - 08-0001
Date - 6/10/08
Name(s): Smith, Jones, Brown

What I get in my Excel sheet:

Tracking Number <<tab>>Date<<tab>>Name
08-0001 <<tab>> 6/10/08 <<tab>> Smith
08-0001 <<tab>> 6/10/08 <<tab>> Jones
08-0001 <<tab>> 6/10/08 <<tab>> Brown

Thanks in advance
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

iggydarsa

Well-known Member
Joined
Jun 28, 2005
Messages
1,734
Office Version
  1. 2019
Platform
  1. Windows
Assuming your columns span from Column A to Column C, you can use something like this:

Code:
Private Sub CommandButton1_Click()
Dim r As Long: r = Range("A" & Rows.Count).End(xlUp).Row + 1
Dim vName As String

For i = 1 To Len(txtName.Text)
    If Not Mid(txtName.Text, i, 1) = "," Then
        vName = vName & Mid(txtName.Text, i, 1)
    Else
        Range("A" & r).Value = txtTrackingNumber.Text
        Range("B" & r).Value = txtDate.Text
        Range("C" & r).Value = Trim(vName)
        r = r + 1
        vName = ""
    End If
Next i
Range("A" & r).Value = txtTrackingNumber.Text
Range("B" & r).Value = txtDate.Text
Range("C" & r).Value = Trim(vName)
r = r + 1
vName = ""
Unload Me
End Sub
 
Upvote 0

Forum statistics

Threads
1,190,783
Messages
5,982,900
Members
439,806
Latest member
ShakeShark1

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
Top