Adding a comma after every 9 characters

grussell070769

New Member
Joined
Sep 12, 2022
Messages
9
Office Version
  1. 2016
Platform
  1. Windows
I need to add a comma after every nine characters that would yield a very large return.

Example: Current Chain of numbers
144849383600226994968816910897204120078656326273603444077371702

Need:
144849383,600226994,968816910,897204120,078656326,273603444,077371702,
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Is the string length always going to be in multiples of nine? My formula might not give the expected results if the length of the input is not in multiples of nine.

Excel Formula:
=TEXTJOIN(",",TRUE,MID(A1,SEQUENCE(ROUNDDOWN(LEN(A1)/9,0),1,0,9)+1,9))&","

I am positive it can be cleaned-up/improved.

Hope that helps,

Doug
 
Upvote 0
Here is a way using PowerQuery.

EXCEL
ABC
1NumbersNumbers
2144849383600226994968816910897204120078656326273603444077371702144849383,600226994,968816910,897204120,078656326,273603444,077371702
3010882765421280172524857202127605316837668282342649953503691010882765,421280172,524857202,127605316,837668282,342649953,503691
46023367054925382409056409728100834015337960373526982734702021602336705,492538240,905640972,810083401,533796037,352698273,4702021
5730335284668288737472789869655295910221946556260013423000966763456730335284,668288737,472789869,655295910,221946556,260013423,000966763,456
6686572419255530859260374435598580500404692808689497106526907314686572419,255530859,260374435,598580500,404692808,689497106,526907314
7473322394931064041827847062669653346095951698024943653223799177473322394,931064041,827847062,669653346,095951698,024943653,223799177
Sheet7


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Insert = Table.TransformColumns(Source,{{"Numbers", (txt)=> 
    let 
        lst = List.Generate(() => 0, each _ <= Number.Round(Text.Length(txt)/10,0), each _ + 1, each _ * 9 + _),
        ins = Text.RemoveRange(List.Accumulate(lst,txt,(s,c)=> Text.Insert(s,c,",")),0)
    in
        ins
    }})
in
    Insert
 
Upvote 0
That's why you get #name as you won't have either textjoin or sequence
 
Upvote 0
In case a vba solution would help (which I think would be not version dependent)
VBA Code:
Function InsertComma(strIn As String) As String
Dim i As Integer, n As Integer
Dim strOut As String

n = 1
For i = 1 To Len(strIn) / 9
     strOut = strOut & Mid(strIn, n, 9) & ","
     n = n + 9
Next
Debug.Print strOut
InsertComma = strOut

End Function
 
Upvote 0
Assuming the length of the string varies, I think VBA is your only option.
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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