Adding a comma between single digits in a cell

lind33

New Member
Joined
Jun 25, 2019
Messages
14
Office Version
  1. 2016
Platform
  1. Windows
I am looking for a way to add a comma after every single digit in a cell.
I found some formulas on the web but since the number of digits is not equal in the cells, I can't get the result I need.

For example, in column A:
12345
12
135789
135
etc.

What formula can give me the result I need? can I get some help, please? thanks.
Expected results of the above example:
1,2,3,4,5
1,2
1,3,5,7,8,9
1,3,5
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Nice, Rick
Thanks!



I hadn't seen that version before.
Me either... I made it up on the spot. In thinking about it now, I vaguely remember doing something in a similar vein in VBA using String and Format a while ago, so maybe that was in the back of my mind when I dummied up the formula for the initial testing.
 
Last edited:
Upvote 0
Thanks!

Me either... I made it up on the spot. In thinking about it now, I vaguely remember doing something in a similar vein in VBA using String and Format a while ago, so maybe that was in the back of my mind when I dummied up the formula for the initial testing.


Congratulations Rick for the ability you have to solve it on the spot. And for sharing it with mortals.
 
Upvote 0
Congratulations Rick for the ability you have to solve it on the spot. And for sharing it with mortals.
Uh, I am one of the mortals also you know. I just got lucky and thought up a simple formula using a somewhat different approach, that is all.
 
Upvote 0
Given the formula I posted in Message #8 , a UDF for this functionality (if one was thought to be necessary now) could be written as a non-looping one-liner...
Code:
Function AddCommas(s As String) As String
  AddCommas = Evaluate(Replace("MID(TEXT(@,REPT(""\,0"",LEN(@))),2,2*LEN(@))", "@", s))
End Function
I know this is an old thread, but I have another way to write the above one-liner...
VBA Code:
Function AddCommas(S As String) As String
  AddCommas = Replace(Trim(Replace(StrConv(S, vbUnicode), Chr(0), " ")), " ", ",")
End Function
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
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