VBA Express Forum  




Go Back   VBA Express Forum > VBA Code & Other Help > Excel Help
     Feedback     
Register FAQ Members Arcade Knowledge Base Training Articles Consulting

Reply
 
Thread Tools Display Modes
Old 04-16-2012, 04:41 AM   #1
clif

 
Joined: Nov 2009
Posts: 65
Kb Entries: 0
Articles: 0
How to combine the text into one cell?

How to combine the text form different cells into one cell (use comma to seperate them)?

A2 Apple
A3 Blue
A4 Cat
A5 1235


Result:

A1 Apple,Blue,Cat,1235

Thank you very much!

Local Time: 07:23 PM
Local Date: 05-18-2013
Location:

 
Reply With Quote Top
Old 04-16-2012, 01:21 PM   #2
Tinbendr
 
Tinbendr's Avatar

 
Joined: Jun 2005
Posts: 983
Kb Entries: 0
Articles: 0
In A1 put
VBA:
=A2&","&A3&","&A4&","&A5
VBA tags courtesy of www.thecodenet.com


+------+
| David |
+------+

Local Time: 05:23 AM
Local Date: 05-18-2013
Location:

 
Reply With Quote Top
Old 04-17-2012, 03:43 AM   #3
BrianMH

 
Joined: Feb 2009
Posts: 481
Kb Entries: 1
Articles: 2
I need to do this quite often and have created a UDF for this. It is handy when working with large numbers of cells and really reduces typing.

It could easily be modified to use something other than "," as a delimiter. You could even have it ask what to use for the delimiter simply enough.

VBA:
Public Function DatatoCSV(rData As Range) As String Dim c As Range Dim strOut As String For Each c In rData.Cells If c.Value <> "" Then If strOut <> "" Then strOut = strOut & ", " End If strOut = strOut & c.Value End If Next DatatoCSV = strOut End Function
VBA tags courtesy of www.thecodenet.com


This does ignore empty cells.


-----------------------------------------
The more you learn about something the more you know you have much to learn.

Local Time: 11:23 AM
Local Date: 05-18-2013
Location:

 
Reply With Quote Top
Old 04-17-2012, 05:11 AM   #4
snb

 
Joined: Apr 2012
Posts: 1,101
Kb Entries: 0
Articles: 4
or
VBA:
Function concat_snb() concat_snb = Join(Filter([transpose(If(A1:A10="","~",A1:A10))], "~", False), ",") End Function
VBA tags courtesy of www.thecodenet.com

or
VBA:
Function concat_snb(c01 As Range) concat_snb = Join(Filter(Evaluate(Replace("transpose(if(#="""", ""~"", #))", "#", c01.Address)), "~", False), ",") End Function
VBA tags courtesy of www.thecodenet.com

Local Time: 01:23 PM
Local Date: 05-18-2013

 
Reply With Quote Top
Old 04-17-2012, 08:03 AM   #5
clif

 
Joined: Nov 2009
Posts: 65
Kb Entries: 0
Articles: 0
How to correct this code?

VBA:
Public Function DatatoCSV(rData As Range) As String Dim c As Range Dim strOut As String For Each c In rData.Cells If c.Value <> "" Then If strOut <> "" Then strOut = strOut & ", " End If strOut = strOut & c.Value End If Next DatatoCSV = strOut End Function Public Sub ProcessData() Dim Lastrow As Long Dim i As Long Dim cell As Range Application.ScreenUpdating = False With ActiveSheet Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row For i = Lastrow - 1 To 2 Step -1 If .Cells(i, "I").Value = 1 Then .Cells(i, "E").Value = .Cells(i, "E").Value + .Cells(i + 1, "E").Value .Cells(i, "F").Value = DatatoCSV(.Cells(i, "F"), .Cells(i + 1, "F").Value) .Cells(i, "G").Value = .Cells(i, "G").Value + .Cells(i + 1, "G").Value .Rows(i + 1).Delete End If Next i End With Application.ScreenUpdating = True End Sub
VBA tags courtesy of www.thecodenet.com

Local Time: 07:23 PM
Local Date: 05-18-2013
Location:

 
Reply With Quote Top
Old 04-18-2012, 05:19 PM   #6
clif

 
Joined: Nov 2009
Posts: 65
Kb Entries: 0
Articles: 0
Anyone can help me?

Local Time: 07:23 PM
Local Date: 05-18-2013
Location:

 
Reply With Quote Top
Old 04-19-2012, 12:25 AM   #7
snb

 
Joined: Apr 2012
Posts: 1,101
Kb Entries: 0
Articles: 4
Did you overlook my suggestion ?

Just to add another one:

VBA:
Function F_concatcol_snb(c01 As range) F_concatcol_snb = Join(Application.Transpose(c01), ",") End Function
VBA tags courtesy of www.thecodenet.com

If you are interested in more have a look over here.

Local Time: 01:23 PM
Local Date: 05-18-2013

 
Reply With Quote Top
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -7. The time now is 04:23 AM.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright © 2004 - 2012 VBA Express