Extract comma separated strings in a cell and write them to different cells

NewOrderFac33

Well-known Member
Joined
Sep 26, 2011
Messages
1,275
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Good afternoon - I have a number of cells containing multiple version strings similar to: "1.10, 1.11, 1.12, 1.14, 1.16.1, 1.8.1, 1.9" (some of them might only contain one e.g. 1.10 with no trailing comma)
I need to be able to replace the contents of the cell with the first value (in this case 1.10) then extract each of the subsequent values (not including any spaces or commas) and write them to the cells immediately below.
So, if this was Cell A1, A1 would end up containing 1.10, A2 would contain 1.11, A3 would contain 1.12 and so on.
Can anyone help me out, please?
Thanks
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Which cells?
Oops - can you not see my original post:
Good afternoon - I have a number of cells containing multiple version strings similar to: "1.10, 1.11, 1.12, 1.14, 1.16.1, 1.8.1, 1.9" (some of them might only contain one e.g. 1.10 with no trailing comma)
I need to be able to replace the contents of the cell with the first value (in this case 1.10) then extract each of the subsequent values (not including any spaces or commas) and write them to the cells immediately below.
So, if this was Cell A1, A1 would end up containing 1.10, A2 would contain 1.11, A3 would contain 1.12 and so on.
Can anyone help me out, please?
Thanks
 
Upvote 0
can you not see my original post:
Yes I can see it, that's why I asked "Which cells" you have said "I have a number of cells" & then given a single example. So my question stands.
 
Upvote 0
Yes I can see it, that's why I asked "Which cells" you have said "I have a number of cells" & then given a single example. So my question stands.
Ah - with you - the range is D:1-D1842. Some of them have multiple values, some don't. I have worked out how to insert the appropriate number of rows below the cell being processed, based on how many commas it has. My problem is around extracting each comma separated value, replacing the original "1.10, 1.11, 1.12" etc. with "1.10" and writing "1.11" into the cell below, "1,12" into the cell below that, and so on.
 
Upvote 0
Ok, how about
VBA Code:
Sub NewOrderFac()
   Dim r As Long, i As Long
   Dim Sp As Variant
   
   For r = Range("D" & Rows.Count).End(xlUp).Row To 1 Step -1
      Sp = Split(Cells(r, 4).Value, ", ")
      i = UBound(Sp)
      If i > 0 Then
         Rows(r).Offset(1).Resize(i).Insert
         Cells(r, 4).Resize(i + 1).Value = Application.Transpose(Sp)
      End If
   Next r
End Sub
 
Upvote 0
Ok, how about
VBA Code:
Sub NewOrderFac()
   Dim r As Long, i As Long
   Dim Sp As Variant
  
   For r = Range("D" & Rows.Count).End(xlUp).Row To 1 Step -1
      Sp = Split(Cells(r, 4).Value, ", ")
      i = UBound(Sp)
      If i > 0 Then
         Rows(r).Offset(1).Resize(i).Insert
         Cells(r, 4).Resize(i + 1).Value = Application.Transpose(Sp)
      End If
   Next r
End Sub
This looks excellent - except for the fact that I've now already inserted the new rows for each multiple entry..! I realise this is being cheeky, but is there any way in which you could adapt this just to work for the selected range of cells - so, for example, if I have "1.1.0, 1.5.6, 1.7.9, 1.8.4" in D1, with D1:D4 selected, D1 would equate to"1.1.0", D2 to "1.5.6", D3 to "1.7.9" and D4 to "1.8.4" - the number of selected cells can be anything between 2 and 20 depending on the number of comma separated values in the first cell, if that makes sense? Thank you - up against a harsh deadline here..!
 
Upvote 0
Try
VBA Code:
Selection.Value = Application.Transpose(Split(ActiveCell, ", "))
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,620
Messages
6,120,554
Members
448,970
Latest member
kennimack

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