Merging cells

KWR

New Member
Joined
Nov 13, 2009
Messages
6
I am looking to merge a column of 630 cells into one cell with the values separated by "_,"

For example

12
13
14
15
16

would merge to: 12_,13_,14_,15_,16_,

Any thoughts on this? Im struggling to automate the macro such that is works for varying amounts of cells (500 in one sheet, 30 in another). Any help would be very much appreciated.
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,651
Try something like

Code:
Sub concat()
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("A" & LR + 1).Value = Join(Application.Transpose(Range("A1:A" & LR).Value), "_,")
End Sub
 

lenze

Legend
Joined
Feb 18, 2002
Messages
13,690
Code:
Sub MergeMe()
Dim m As String
Dim cl As Range
For Each cl In Selection
m = m & cl & "_,"
Next cl
m = Left(m, Len(m) - 3)
Range("$B$2") = m
End Sub
lenze
 

KWR

New Member
Joined
Nov 13, 2009
Messages
6
THanks for the quick response. It doesnt seem to be working with numbers stored as text, is there any way to make it work with both standard numbers and those stored as text? Thanks
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,651
With numbers stored as text

<b>Sheet1</b><br /><br /><table border="1" cellspacing="0" cellpadding="0" style="font-family:Calibri,Arial; font-size:11pt; background-color:#ffffff; padding-left:2pt; padding-right:2pt; "> <colgroup><col style="font-weight:bold; width:30px; " /><col style="width:158px;" /></colgroup><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td > </td><td style=" border-width:3px; border-style:eek:utset;border-color:#f0f0f0; ">A</td></tr><tr style="height:18px ;" ><td style="border-width:3; border-style:eek:utset;border-color:#f0f0f0; background-color:#cacaca; text-align:center; " >1</td><td style="text-align:right; ">12</td></tr><tr style="height:18px ;" ><td style="border-width:3; border-style:eek:utset;border-color:#f0f0f0; background-color:#cacaca; text-align:center; " >2</td><td style="text-align:right; ">13</td></tr><tr style="height:18px ;" ><td style="border-width:3; border-style:eek:utset;border-color:#f0f0f0; background-color:#cacaca; text-align:center; " >3</td><td style="text-align:right; ">14</td></tr><tr style="height:18px ;" ><td style="border-width:3; border-style:eek:utset;border-color:#f0f0f0; background-color:#cacaca; text-align:center; " >4</td><td style="text-align:right; ">15</td></tr><tr style="height:18px ;" ><td style="border-width:3; border-style:eek:utset;border-color:#f0f0f0; background-color:#cacaca; text-align:center; " >5</td><td style="text-align:right; ">16</td></tr><tr style="height:18px ;" ><td style="border-width:3; border-style:eek:utset;border-color:#f0f0f0; background-color:#cacaca; text-align:center; " >6</td><td >12_,13_,14_,15_,16</td></tr></table> <br />Excel tables to the web - Excel Jeanie Html 4
 

KWR

New Member
Joined
Nov 13, 2009
Messages
6
nevermind. I got it working. Thanks a lot for all of the help. Just saved me a TON of time. Thanks!
 

lenze

Legend
Joined
Feb 18, 2002
Messages
13,690
Did you try the one I posted? It seems to work, but change the 3 to as 2. BTW, Peter's code also works for me

lenze
 

Forum statistics

Threads
1,081,528
Messages
5,359,299
Members
400,524
Latest member
Excelbat

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top