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

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

QuietRiot

Well-known Member
Joined
May 18, 2007
Messages
1,079
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. MacOS
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
 

QuietRiot

Well-known Member
Joined
May 18, 2007
Messages
1,079
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. MacOS
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
 

Forum statistics

Threads
1,181,055
Messages
5,927,862
Members
436,573
Latest member
CMR237

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
Top