Split the content of a cell into separate rows

Bering

Board Regular
Joined
Aug 22, 2018
Messages
185
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have to review a reconciliation file similar to the one below. The problem is that in column 5 (Comment) there could be cells that include a number of items, which makes it impossible for me to filter/analyse the data, (i.e. comments for item #3 ).

Whenever a comment contains several items, each item is identified by a consecutive number followed by a dot.

For example, for item 3, the comment provides a break-down of the -51 difference as:

1. 5 missing instruction
2. 15 incorrect posting,
3. 31 timing difference


ItemOur quantityTheir quantityDifferenceComment
12030-10Timing difference
230255Under investigation
3960-511. 5 missing instruction 2. 15 incorrect posting, 3. 31 timing difference
41010-No difference

<tbody>
</tbody>


Is there a way (vba, formulae, text to column..) to split the content of such cells into separate rows so that the result looks be something like this:


ItemOur quantityTheir quantityDifferenceComment
12030-10Timing difference
230255Under investigation
3960-511. 5 missing instruction
3960-512. 15 incorrect posting,
3960-513. 31 timing difference
41010-No difference

<tbody>
</tbody>

Thanks for any suggestions.
 
Hi Peter... I was wondering if you could help me again. Not sure if I should open a new thread...

I would like amend the code
Code:
.Pattern = "\*[^\*]+"
to include the scenario where there is an Alt+Enter (CHAR(10)) between each numbered point

Thank you.
Not a new thread as this is just a continuation of the existing issue.

If you have Alt-Enter between points, but presumably not before the first point, and you still want to use RegExp then try this. Apart from a new Pattern line, I have compacted the code a little.

Code:
Sub Split_Rows_Reg_Exp_v2()
  Dim a As Variant, b As Variant, m As Variant
  Dim i As Long, j As Long, k As Long, uba2 As Long
  
  a = Range("A1", Range("E" & Rows.Count).End(xlUp)).Value
  uba2 = UBound(a, 2)
  ReDim b(1 To UBound(a) * 20, 1 To uba2)
  With CreateObject("VBScript.RegExp")
    .Global = True
    .Pattern = Chr(10) & "*[^" & Chr(10) & "]+"
    For i = 1 To UBound(a)
      For Each m In .Execute(a(i, uba2))
        k = k + 1
        For j = 1 To uba2 - 1
          b(k, j) = a(i, j)
        Next j
        b(k, uba2) = Trim(m)
      Next m
    Next i
  End With
  Range("A" & Rows.Count).End(xlUp).Offset(3).Resize(k, uba2).Value = b
End Sub
 
Upvote 0
Solution

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,214,399
Messages
6,119,279
Members
448,884
Latest member
chuffman431a

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