• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Concatenate range of data into one cell

nagovind

Member
Dear All,

There are strings/ numbers (irrespective of data type) in cells say

A1 = Apple
B1 = 2435
C1 = Google
E1 = MSoffice
..
..
..
K1 = $240@04

The requirement is to concatenate all those data in to a cell say B1 separated by comma

Cell B1 shall contain Apple,2435,Google,MSoffice,.......,$240@04

Please advise

Thank you
Govind
 
You could do the following, however, you will have a problem if the data includes a date

= A1&","&B1&","&C1&","&E1......
 
Hi,

'cause it's the VBA Macros section a code example :​
Code:
    [B1].Value = Join(Application.Index([A1:K2].Value, 1), ",")
 
@kchiba
Actually i need versatile program so that range has to be modified as required
So i need a VBA code

@ Marc L
Sub chk()
[B1].Value = Join(Application.Index([A1:A10].Value, 1), ":")
End Sub

I have used your code as above with the data in the cells A1 to A10
But there is no results in B1 after executing the code
Please advise
 
Try the following,

it assumes that your data in is Row 1 starting Column A
and your result is in A3


Code:
Sub ConCat_Range()
Dim rng As Range
Dim lr As Integer
Range("a3").Clear
Set rng = Range("A1").CurrentRegion
lr = rng(rng.Count).Column
For Each r In rng
  Range("A3").Value = Range("A3").Value & "," & r
Next r
End Sub
 
@ Marc L
I have used your code as above with the data in the cells A1 to A10
But there is no results in B1 after executing the code
Please advise
Your original post was for A1:K1 ‼

So you can adapt, just read the INDEX's help since the worksheet' screen …
 
Last edited:
Hi Marc,

I am sure I am missing something but your code only picks up A1, would really like to see it work, it looks cool.

cheers

kanti
 
Try the following,

it assumes that your data in is Row 1 starting Column A
and your result is in A3


Code:
Sub ConCat_Range()
Dim rng As Range
Dim lr As Integer
Range("a3").Clear
Set rng = Range("A1").CurrentRegion
lr = rng(rng.Count).Column
For Each r In rng
  Range("A3").Value = Range("A3").Value & "," & r
Next r
End Sub

Thank you for your reply

Your code works
1. But it adds a 'comma' even for first cell data
2. Please advise how to modify the code such that the data is in the subsequent ROWS instead of columns

Sincerely
Govind
 
Thank you for your reply

Your code works
1. But it adds a 'comma' even for first cell data
2. Please advise how to modify the code such that the data is in the subsequent ROWS instead of columns

Sincerely
Govind


Wow

IT is working perfectly irrespective of the data is in row or columns

But please advise how to make it ONLY row data to be concatenated or Only column data to be concatenated
 
Not sure what you mean by only ROW or only Column, if your data is in a column the column will be concatenated, if the data is in a row the row will be concatenated.

The thing is the Row or Column must be stand alone and not have other data adjacent to it. So please upload a file and spell out exactly what you need.
 

My code example is for a row data and can be easily adapted for a column
just by reading the INDEX worksheet function's help ! …​
 
Not sure what you mean by only ROW or only Column, if your data is in a column the column will be concatenated, if the data is in a row the row will be concatenated.

The thing is the Row or Column must be stand alone and not have other data adjacent to it. So please upload a file and spell out exactly what you need.


Thank you for your reply

"The thing is the Row or Column must be stand alone and not have other data adjacent to it"

Agreed

Closed. Thanks for the code
 
Back
Top