PDA

View Full Version : Create a single cell from a column of number



Vurtnebrak
02-27-2012, 07:27 PM
I need to create a single cell with a semicolon in between each number from a column of numbers. The list will continually vary in length. Is there a macro or formula that can do this?
Example

17020
17021
17030
17031

Result in a single cell is 17020;17021;17030;17031

Thanks

JimmyTheHand
02-27-2012, 09:46 PM
Try this code, and alter it as desired:
Range("B1")=Join(Application.Transpose(Range("A1:A4")),";")
Jimmy

JKwan
02-28-2012, 08:50 AM
Alternatives:
Sub MergeCells()
Dim LastRow As Long

' if you don't know how many rows there will be, use this
LastRow = FindLastRow(ActiveSheet, "A")
Range("B1") = Join(Application.Transpose(Range("A1:A" & LastRow)), ";")

' or you can select what you want to merge
If Selection.Count > 1 Then
Range("B2") = Join(Application.Transpose(Selection), ";")
Else
Range("B2") = ActiveCell.Value
End If
End Sub
Public Function FindLastRow(ByVal WS As Worksheet, ColumnLetter As String) As Long
FindLastRow = WS.Range(ColumnLetter & "65536").End(xlUp).Row
End Function