Turn number into comma separated series

Darth Emphatic

New Member
Joined
Jan 31, 2010
Messages
14
Office Version
  1. 2016
Platform
  1. Windows
Not sure if this is possible in excel, which is my preferred place to do it, but I could do in another way if needed. I found another thread on the forums with a similar question, that someone then suggests viewing another forum thread, but when I click on that link, it just routes to the message board home page for me:


In a a set of rows, I have numbers like below:

1
4
3
2

What I want to do is convert those into comma delimited sequences starting at the last number in the previous row. The above would look like:

1
2,3,4,5
6,7,8
9,10
 

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
Hi!

Could you please upload a sample Excel file where you have two sheets (for example), one with the original data and one with the "new" data.
Would be much easier to see what your aim is.
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Also can you post a larger sample of your data.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
Another way using VBA.

VBA Code:
Sub TCS()
Dim r As Range:         Set r = Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
Dim AR() As Variant:    AR = r.Value2
Dim POS As Integer:     POS = 1
Dim SD As Object:       Set SD = CreateObject("Scripting.Dictionary")
Dim tmp As String

For i = 1 To UBound(AR)
    For j = POS To POS + AR(i, 1) - 1
        tmp = tmp & j & ","
    Next j
    SD.Add Left(tmp, Len(tmp) - 1), 1
    tmp = vbNullString
    POS = POS + AR(i, 1)
Next i

r.Offset(, 1).Value = Application.Transpose(SD.keys)
End Sub
 
Upvote 0
This was fun!

New Microsoft Excel Worksheet (2).xlsx
AB
111
242,3,4,5
336,7,8
429,10
Sheet6
Cell Formulas
RangeFormula
B1:B4B1=MID(CONCAT(SEQUENCE(A1,1,SUM($A$1:A1)-A1+1)&","),1,LEN(CONCAT(SEQUENCE(A1,1,SUM($A$1:A1)-A1+1)&","))-1)
 
Upvote 0
This was fun!

New Microsoft Excel Worksheet (2).xlsx
AB
115
242,3,4,5,
336,7,8,
429,10,
Sheet6
Cell Formulas
RangeFormula
B1B1=MID(CONCAT(SEQUENCE(A1,1,SUM($A$1:A2)-A1+1)&","),1,LEN(CONCAT(SEQUENCE(A1,1,SUM($A$1:A2)-A1+1)&","))-1)
B2:B4B2=CONCAT(SEQUENCE(A2,1,SUM($A$1:A2)-A2+1)&",")
Doesn't appear to be quite right.
B1 shows "5" instead of "1", and you have extra commas at the end of the rest of the rows.
 
Upvote 0
Doesn't appear to be quite right.
B1 shows "5" instead of "1", and you have extra commas at the end of the rest of the rows.
I just fixed it. (I noticed that too, thanks!)
 
Upvote 0
And Power Query, why not?

Book2 (version 1).xlsb
ABCD
1NumsNumsCustom
2111
3442,3,4,5
4336,7,8
5229,10
Sheet9


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Index = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
    RT = Table.AddColumn(Index, "RT", each List.Sum(List.FirstN(Index[Nums],[Index]))),
    Dif = Table.AddColumn(RT, "Dif", each [RT]-[Nums]+1),
    Combine = Table.AddColumn(Dif, "Custom", each Text.Combine(List.Transform({[Dif]..[RT]},Text.From),",")),
    RC = Table.RemoveColumns(Combine,{"Index", "RT", "Dif"})
in
    RC
 
Upvote 0

Forum statistics

Threads
1,215,096
Messages
6,123,074
Members
449,093
Latest member
ripvw

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