Transpose data and insert a coma in between

kittyfur

New Member
Joined
May 29, 2007
Messages
3
Hello
I have a list of account numbers in Excel, like this:
123
234
345
456
567
678

Do you know how to code a macro so it can end up in ONE cell looking like this:
123,234,345,456,567,678

Thanks!
Jenny
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
this will look down column A and then put the answer in B1

Code:
Sub Macro1()
Dim hey As String, num As String


Set C = Cells.Find(What:="*", After:=[A1], SearchDirection:=xlPrevious)
If C Is Nothing Then
    last = 1
Else
    last = C.Row
End If

For x = 1 To last

num = Cells(x, 1).Value
If x < last Then
hey = hey + num + ","
Else
hey = hey + num
End If
Next

Cells(1, 2).Formula = hey


End Sub
 
Upvote 0
hmm, i just realized you probalby don't know how to use a macro?

sorry I just whipped it up real quick im not sure how to do it non-macro

but hit Alt + F11 and paste that above code in there then exit.

make sure numbers are in A column and B1 is blank

then go to tools > macro> macros > and run Macro1
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,921
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top