Separating lists of data in one cell to multiple rows

shebe228

New Member
Joined
Sep 28, 2017
Messages
46
I received a spreadsheet that was submitted from an outside source. I have invoices in one column then the line items of that invoice all in one cell to the right, then the corresponding charges. Is there any way to separate the codes and charges to be in separate cells on multiple rows?


There is no space between the codes to do a find/replace then text to columns. Each invoice has varying number of codes/charges

This is what I have:

InvoiceCodeCharges
7985132198797110
97140
aa75861
90.00
70.00
8.00
654321884asdf83476
97082
155.00
2.22
654651354798797124
97812
97124
79124
97127
94157
65486
65489
100.00
500.00
50.00
50.00
50.00
50.00
50.00
50.00

<tbody>
</tbody>




This is what I want:
InvoiceCodeCharges
798513219879711090.00
9714070.00
aa758618.00
654321884asdf83476155.00
970822.22

<tbody>
</tbody>
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
In an unused cell enter
=CODE(MID(B2,6,1))
change the B2 to point at the cell that contains
97110
97140
aa75861

What does the formula return
 
Upvote 0
I was able to get the separate the data into multiple columns. Now I need to transpose those columns back to one column. The varying number of columns on each row is what is throwing me off. Suggestions?

My data looks like this:
Invoice123456789
ABC9711097140AAGRT
BCD99213AAGRT
CDE9712497124971249712497124971249712497124AAGRT

<tbody>
</tbody>



and I want it to look like this
InvoiceCode
ABC97110
97140
AAGRT
BCD99213
AAGRT
CDE97124
97124
97124
97124
97124
97124
97124
97124
AAGRT

<tbody>
</tbody>
 
Upvote 0
How about
Code:
Sub Splitrws()
   Dim i As Long, x As Long
   
   For i = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
      x = Application.Max(UBound(Split(Cells(i, 2), Chr(10))), UBound(Split(Cells(i, 3), Chr(10))))
      If x > 0 Then
         Rows(i + 1).Resize(x).Insert
         Cells(i, 2).Resize(x + 1).Value = Application.Transpose(Split(Cells(i, 2), Chr(10)))
         Cells(i, 3).Resize(x + 1).Value = Application.Transpose(Split(Cells(i, 3), Chr(10)))
      End If
   Next i
End Sub
Run this on your original data.
 
Upvote 0
How about
Code:
Sub Splitrws()
   Dim i As Long, x As Long
   
   For i = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
      x = Application.Max(UBound(Split(Cells(i, 2), Chr(10))), UBound(Split(Cells(i, 3), Chr(10))))
      If x > 0 Then
         Rows(i + 1).Resize(x).Insert
         Cells(i, 2).Resize(x + 1).Value = Application.Transpose(Split(Cells(i, 2), Chr(10)))
         Cells(i, 3).Resize(x + 1).Value = Application.Transpose(Split(Cells(i, 3), Chr(10)))
      End If
   Next i
End Sub
Run this on your original data.


Thanks!! I took the long way around, but it worked. :) Thank you for your help!!
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,535
Members
449,037
Latest member
tmmotairi

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