Create a new row/s for a multiple value/s in a cell

htou

New Member
Joined
Oct 31, 2002
Messages
34
Hello folks,

Looking for a solution to the following via a script or excel formulas/functions etc and im a complete excel noob.

I have a worksheet that contains about 2,300 lines/rows of property data. The data in Column H is my issue. What is consistent in this column is the comma symbol. If there is a comma present, then there is more than one value. I need each value after the comma to have its own row after the subject/original cell.

Once a new row is created for the value/s, the data in the row containing the multiple value are duplicated to the empty cells of the newly created row. Hope that makes sense, hopefully my sample below paints a better picture.

Column H, cells containing multiple values represented by a comma -

Excel 2010
ABCDEFGHI
1RefTypeLADTenure RefLGDORegLot_PlanArea (ha)
217645107GHPL373239CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST15PT41,19PT278,20PT279,42PT279,38PT280,14PT412923.36
317645108GHPL373240CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST6PLA4011558.466
417645109GHPL373241CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST13TT228,17TT2282577.089
517645113GHPL373245CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST5BU26,2BU1711029.66
617645114GHPL373246CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST1BU176623.616
717645115GHPL373250CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST21DSN1141079.904
817645116GHPL373251CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST12DSN647,6DSN6474752.489
917645125GHPL373269CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST27DSN8364474311.353
1017645127GHPL373274CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST57PT25,55PT25,56PT25,58PT251572.988
1117645128GHPL373275CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST69DSN1441200.222
1217645130GHPL373279CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST8PT346,6PT23,7PT3471948.911
Sheet1

What it should look like after a solution is deployed, multiple values that were in specific cells in Column H now have a new row and information duplicated into the empty fields-

Excel 2010
ABCDEFGHI
1RefTypeLADTenure RefLGDORegLot_PlanArea (ha)
217645107GHPL373239CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST15PT412923.36
317645107GHPL373239CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST19PT2782923.36
417645107GHPL373239CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST20PT2792923.36
517645107GHPL373239CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST42PT2792923.36
617645107GHPL373239CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST38PT2802923.36
717645107GHPL373239CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST14PT412923.36
817645108GHPL373240CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST6PLA4011558.466
917645109GHPL373241CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST13TT2282577.089
1017645109GHPL373241CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST17TT2282577.089
1117645113GHPL373245CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST5BU2611029.66
1217645113GHPL373245CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST2BU1711029.66
1317645114GHPL373246CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST1BU176623.616
1417645115GHPL373250CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST21DSN1141079.904
1517645116GHPL373251CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST12DSN6474752.489
1617645116GHPL373251CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST6DSN6474752.489
1717645125GHPL373269CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST27DSN8364474311.353
1817645127GHPL373274CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST57PT251572.988
1917645127GHPL373274CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST55PT251572.988
2017645127GHPL373274CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST56PT251572.988
2117645127GHPL373274CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST58PT251572.988
2217645128GHPL373275CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST69DSN1441200.222
2317645130GHPL373279CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST8PT3461948.911
2417645130GHPL373279CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST6PT231948.911
2517645130GHPL373279CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST7PT3471948.911
Sheet2
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
The creation of your macro could be tedious but I think it's possible. A little pseudo-code to begin:

1) Need to count the number of commas in each H column cell. The syntax below is admittedly "rough".

Code:
Sub CountCommas()
    For Each rRow In iTotalHRows
        For iChar = 1 To Len(rRow)
            If Mid(rRow, iChar, 1) = "," Then
                iCount = iCount + 1
            End If
        Next iChar
        If iCount = 0 Then
        Else
            'Insert number of rows equal to iCount
        End If
    Next rRow
End Sub

2) Once number of commas known, insert number of rows below equal to the number of commas.
3) Parse out the words in between the commas so they can then be inserted into the new (now blank) rows.
4) Copy down all the duplicate data.

This will get you started. Happy to continue if need be, just write back.
 
Upvote 0
htou,

Sample worksheets:


Excel 2007
ABCDEFGHI
1RefTypeLADTenure RefLGDORegLot_PlanArea (ha)
217645107GHPL373239CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST15PT41,19PT278,20PT279,42PT279,38PT280,14PT412923.36
317645108GHPL373240CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST6PLA4011558.466
417645109GHPL373241CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST13TT228,17TT2282577.089
517645113GHPL373245CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST5BU26,2BU1711029.66
617645114GHPL373246CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST1BU176623.616
717645115GHPL373250CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST21DSN1141079.904
817645116GHPL373251CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST12DSN647,6DSN6474752.489
917645125GHPL373269CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST27DSN8364474311.353
1017645127GHPL373274CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST57PT25,55PT25,56PT25,58PT251572.988
1117645128GHPL373275CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST69DSN1441200.222
1217645130GHPL373279CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST8PT346,6PT23,7PT3471948.911
13
Sheet1



Excel 2007
ABCDEFGHI
1RefTypeLADTenure RefLGDORegLot_PlanArea (ha)
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Sheet2


After the macro in Sheet2:


Excel 2007
ABCDEFGHI
1RefTypeLADTenure RefLGDORegLot_PlanArea (ha)
217645107GHPL373239CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST15PT412923.36
317645107GHPL373239CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST19PT2782923.36
417645107GHPL373239CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST20PT2792923.36
517645107GHPL373239CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST42PT2792923.36
617645107GHPL373239CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST38PT2802923.36
717645107GHPL373239CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST14PT412923.36
817645108GHPL373240CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST6PLA4011558.466
917645109GHPL373241CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST13TT2282577.089
1017645109GHPL373241CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST17TT2282577.089
1117645113GHPL373245CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST5BU2611029.66
1217645113GHPL373245CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST2BU1711029.66
1317645114GHPL373246CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST1BU176623.616
1417645115GHPL373250CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST21DSN1141079.904
1517645116GHPL373251CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST12DSN6474752.489
1617645116GHPL373251CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST6DSN6474752.489
1717645125GHPL373269CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST27DSN8364474311.353
1817645127GHPL373274CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST57PT251572.988
1917645127GHPL373274CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST55PT251572.988
2017645127GHPL373274CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST56PT251572.988
2117645127GHPL373274CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST58PT251572.988
2217645128GHPL373275CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST69DSN1441200.222
2317645130GHPL373279CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST8PT3461948.911
2417645130GHPL373279CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST6PT231948.911
2517645130GHPL373279CENTRAL HIGHLANDS RCEMERALDCENTRAL WEST7PT3471948.911
26
Sheet2


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub Expand_Lot_Plan()
' hiker95, 12/03/2014, ME821931
Dim w1 As Worksheet, w2 As Worksheet
Dim c As Range, nr As Long
Dim s, i As Long
Application.ScreenUpdating = False
Set w1 = Sheets("Sheet1")
Set w2 = Sheets("Sheet2")
w2.Range("A2", w2.Range("A2").End(xlDown)).Resize(, 9).ClearContents
nr = 1
With w1
  For Each c In .Range("H2", .Range("H" & Rows.Count).End(xlUp))
    If InStr(c, ",") Then
      nr = nr + 1
      s = Split(c, ",")
      w2.Cells(nr, 1).Resize(UBound(s) + 1, 7).Value = .Cells(c.Row, 1).Resize(, 7).Value
      w2.Cells(nr, 8).Resize(UBound(s) + 1).Value = Application.Transpose(s)
      w2.Cells(nr, 9).Resize(UBound(s) + 1).Value = .Cells(c.Row, 9).Value
      nr = nr + UBound(s)
    Else
      nr = nr + 1
      w2.Cells(nr, 1).Resize(, 9).Value = .Cells(c.Row, 1).Resize(, 9).Value
    End If
  Next c
End With
With w2
  .UsedRange.Columns.AutoFit
  .Activate
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the Expand_Lot_Plan macro.
 
Upvote 0
@tzw1378 thanks for the suggestion, im assuming the syntax is inserted into a new Module for the sheet? I tried this and i couldn't see any changes. More than likely im executing it wrong.

@hiker95 thank you. Your solution worked perfectly on the sample. Ill deploy it onto the larger set of data when am at work today.

Thank you again to you both for the help, much appreciated.
 
Upvote 0
htou,

@hiker95 thank you. Your solution worked perfectly on the sample.

It is always best to display your actual raw data worksheet(s), and, the results that you are looking for. This way we can usually find a solution on the first go.

Ill deploy it onto the larger set of data when am at work today.

If the macro does not work correctly on your larger set of data, then:

We will have to see your actual raw data.

You can upload your workbook to Box Net,

sensitive data changed

mark the workbook for sharing

and provide us with a link to your workbook.
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,200
Members
449,072
Latest member
DW Draft

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