Splitting values from one cell to multiple rows with the same booking information

excelnewbielearning

New Member
Joined
Sep 15, 2017
Messages
1
Hello there,:)


I recently started learning excel and am having some troubles, I was hoping someone could help me.



I can't fully divulge all the field names and information but to give a simple idea what I essentially have is,


A user inputs data into cells on a user form, these cells are then recorded onto another excel sheet via the use of a macro - user clicks 'book' and the booking information is logged in the second sheet. However, my problem is that in the user form the table cell has more than one values separated by commas. I need to record each of those values with the same booking information from the other cells.


Please see below for clarification:


Tab 1 User form -

Booking name:Booking 1
Tables required:101, 106, 108

<tbody>
</tbody>




I need the information above to appear in the second tab as below -


Tab 2 Booking entries -

Booking 1101
Booking 1106
Booking 1108

<tbody>
</tbody>



I have tried using a macro and copy and pasting the fields from the user's form onto the booking entries form 3 times and then removing the values on each row. But that only appears to work if I only ever have 3 values in my table required field.

Please help if possible. Thank you.

Best wishes,
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Code:
Option Explicit

Sub SplitEntries()

    Dim wksInput As Worksheet
    Dim wksOutput As Worksheet
    Dim lNextWriteRow As Long
    Dim arySplit As Variant
    Dim lSplitIndex As Long
    Dim sName As String
    
    Set wksInput = Worksheets("Sheet1")
    Set wksOutput = Worksheets("Sheet2")
    
    With wksOutput
        lNextWriteRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    End With
    
    sName = wksInput.Range("cellName").Value
    arySplit = Split(wksInput.Range("cellTables").Value, ",")
    
    For lSplitIndex = LBound(arySplit) To UBound(arySplit)
        lNextWriteRow = lNextWriteRow + 1
        wksOutput.Cells(lNextWriteRow, 1).Value = sName
        wksOutput.Cells(lNextWriteRow, 2).Value = Trim(arySplit(lSplitIndex))
    Next
    
    wksInput.Range("cellName").ClearContents
    wksInput.Range("cellTables").ClearContents
    
    Set wksInput = Nothing
    Set wksOutput = Nothing
    
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,102
Messages
6,123,099
Members
449,096
Latest member
provoking

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