Formula or code for combines numbers with comma

Vishaal

Active Member
Joined
Mar 16, 2019
Messages
288
Hi All,

We have the following sheet

Excel 2010 32 bit
A
B
C
1
2
1​
25​
75​
3
2​
36​
74​
4
3​
65​
71​
5
4​
45​
72​
6
5​
82​
7​
7
6​
36​
37​
8
7​
59​
64​
9
8​
54​
98​
10
9​
52​
7​
11
10​
14​
8​
12
11​
58​
1​
13
12​
47​
2​
Sheet: Sheet1

We want to combine the data B2:C13 in D2 and its paste special value in E2

something like this 25,36,65,45,82

data will be increase from B2:C160
 

Some videos you may like

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
8,917
Office Version
2019
Platform
Windows
In excel 2019 or office 365, either

=TEXTJOIN(",",1,B2:C13)

or, array confirmed with Ctrl Shift Enter

=TEXTJOIN(",",1,TRANSPOSE(B2:C13))

In older versions
Code:
Public Function aconcat(a As Variant, Optional sep As String = "") As String
' Harlan Grove, Mar 2002
Dim y As Variant
If TypeOf a Is Range Then
    For Each y In a.Cells
        aconcat = aconcat & y.Value & sep
    Next y
ElseIf IsArray(a) Then
    For Each y In a
        aconcat = aconcat & y & sep
    Next y
Else
    aconcat = aconcat & a & sep
End If
    aconcat = Left(aconcat, Len(aconcat) - Len(sep))
End Function
=ACONCAT(B2:C13,",")

Note that only the second of the 3 methods suggested will produce the exact same format as you specified.
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
44,401
Office Version
365
Platform
Windows
.. another slight variation
=TEXTJOIN(",",1,B2:B13)&","&TEXTJOIN(",",1,C2:C13)
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
5,617
Office Version
365
Platform
Windows
If sequence is important, then consider the following

=TEXTJOIN(",",,B2:C13)
25,75,36,74,65,71,45,72,82,7,36,37,59,64,54,98,52,7,14,8,58,1,47,2
B2, C2, B3, C3......B13, C13

=TEXTJOIN(",",,B2:B13)&"," &TEXTJOIN(",",,C2:C13)

25,36,65,45,82,36,59,54,52,14,58,47,75,74,71,72,7,37,64,98,7,8,1,2
B2,B3.....B13, C2, C3 .....C13


ah - @Peter_SSs got in first :LOL:
 
Last edited:

Vishaal

Active Member
Joined
Mar 16, 2019
Messages
288
please check the error, no value are coming

Excel 2010 32 bit
A
B
C
D
E
1
2
1​
25​
75​
=TEXTJOIN(",",,B2:C13)
Yongle
3
2​
36​
74​
=TEXTJOIN(",",1,B2:B13)&","&TEXTJOIN(",",1,C2:C13)
Peter_SSs
4
3​
65​
71​
=TEXTJOIN(",",1,B2:C13)
jasonb75
5
4​
45​
72​
6
5​
82​
7​
7
6​
36​
37​
8
7​
59​
64​
9
8​
54​
98​
10
9​
52​
7​
11
10​
14​
8​
12
11​
58​
1​
13
12​
47​
2​
Sheet: Sheet1

IInd

Excel 2010 32 bit
A
B
C
D
E
1
2
1​
25​
75​
#NAME?
Yongle
3
2​
36​
74​
#NAME?
Peter_SSs
4
3​
65​
71​
#NAME?
jasonb75
5
4​
45​
72​
6
5​
82​
7​
7
6​
36​
37​
8
7​
59​
64​
9
8​
54​
98​
10
9​
52​
7​
11
10​
14​
8​
12
11​
58​
1​
13
12​
47​
2​
Sheet: Sheet1
 
Last edited:

Tom.Jones

Active Member
Joined
Sep 20, 2011
Messages
252
Hi,

TextJoin appeared with Excel 2016.
Looks like you're using an older version of excel.
if you have Excel 2016 or higher then maybe because of the regional settings.
Change, in the formula "," with ";" obviously without the quotation marks.
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
44,401
Office Version
365
Platform
Windows
please check the error, no value are coming
You were given the following but have not commented on that ..

In excel 2019 or office 365, either

=TEXTJOIN(",",1,B2:C13)

or, array confirmed with Ctrl Shift Enter

=TEXTJOIN(",",1,TRANSPOSE(B2:C13))

In older versions
Code:
Public Function aconcat(a As Variant, Optional sep As String = "") As String
' Harlan Grove, Mar 2002
Dim y As Variant
If TypeOf a Is Range Then
    For Each y In a.Cells
        aconcat = aconcat & y.Value & sep
    Next y
ElseIf IsArray(a) Then
    For Each y In a
        aconcat = aconcat & y & sep
    Next y
Else
    aconcat = aconcat & a & sep
End If
    aconcat = Left(aconcat, Len(aconcat) - Len(sep))
End Function
=ACONCAT(B2:C13,",")
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
5,617
Office Version
365
Platform
Windows
@jasonb75 qualified his solution with "in excel 2019 or office 365 "
explanation:
#NAME? error tells you that the function is not available in your version of Excel (= Excel cannot find function with that NAME)
 
Last edited:

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
44,401
Office Version
365
Platform
Windows
.. regional settings.
Change, in the formula "," with ";"
That issue wouldn't normally result in the #NAME ? error though.


Another option is to go back to basics. :)

=B2&","&B3&","&B4&","&B5&","&B6&","&B7&","&B8&","&B9&","&B10&","&B11&","&B12&","&B13&","&C2&","&C3&","&C4&","&C5&","&C6&","&C7&","&C8&","&C9&","&C10&","&C11&","&C12&","&C13
 

Vishaal

Active Member
Joined
Mar 16, 2019
Messages
288
Excel 2010

Another option is to go back to basics. :) only this option...:ROFLMAO:
 

Watch MrExcel Video

Forum statistics

Threads
1,095,176
Messages
5,442,836
Members
405,201
Latest member
kashyap44

This Week's Hot Topics

  • Copy entire row if CountA <>0 to another sheet
    [B]I want to copy entire row if CountA <>0 for column J7:AM7 (headers on J6:AM6) and so on till the last used cell is column D and paste the...
  • Select last used Row in Table
    I have created a Table in a Worksheet which is locked to prevent user errors and protect formula. Some of the cells require freetext entries which...
  • excel workbook: do not allow certain file name
    Hello all, Don't think this has ever been asked before, but how do I restrict file save [Before_Save Event] if the name of the file being saved...
  • fixing problem autofilter
    hello i need help about my code when i search by code in textbox it doesn't show anything this is my data [ATTACH type="full"...
  • “Weight”
    Hi, i’ve got a long sheet filled with weights such as kg,g,L & ml. i can build a formula to convert kg into g and liter into ml. How ever, my...
  • How to capitalize everything before a certain character?
    In column A, I have some text: Hello good day.mp3 Hello good day.flac etc. I'd like to capitalize everything before the period. I don't need the...
Top