How to move cell values from multiple cells into 1 cell, and separate values by semicolon

kit99

Active Member
Joined
Mar 17, 2015
Messages
352
In excel column A, I have som numbers, for example cell A1 to A6 like this:
98765
87654
76543
65432
54321
43210


My challenge is that I want to move all the numbers in column A (down to last cell with value) into cell A1, separating cell values with a semicolon (without spaces). For example cell A1 like this:
98765; 87654; 76543; 65432; 54321; 43210

Anyone know a vba that can do this job?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Try this:
Code:
Sub Move()
Application.ScreenUpdating = False
Dim i As Integer
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 2 To Lastrow
        Cells(1, 1).Value = Cells(1, 1).Value & ";" & Cells(i, 1).Value
    Next
Application.ScreenUpdating = True

End Sub
Your post said with no spaces but then your sample showed spaces. If you want spaces let me know
 
Last edited:
Upvote 0
Try this:
Code:
Sub Move()
Application.ScreenUpdating = False
Dim i As Integer
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 2 To Lastrow
        Cells(1, 1).Value = Cells(1, 1).Value & ";" & Cells(i, 1).Value
    Next
Application.ScreenUpdating = True

End Sub
Your post said with no spaces but then your sample showed spaces. If you want spaces let me know


Works great!
Thanks a lot :)

But while you're still online..., which part of the vba must change if I want the data to appear in cell C1 instead of A1?
 
Upvote 0
Try this:
Code:
Sub Move()
Application.ScreenUpdating = False
'Version 2
Dim i As Integer
Dim b As String
b = Cells(1, 1).Value
Dim Lastrow As Long

Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 2 To Lastrow
        Cells(1, 1).Value = Cells(1, 1).Value & ";" & Cells(i, 1).Value
    Next
    Cells(1, 3).Value = Cells(1, 1).Value
    Cells(1, 1).Value = b
Application.ScreenUpdating = True

End Sub
 
Upvote 0
Works great!
Thanks a lot :)

But while you're still online..., which part of the vba must change if I want the data to appear in cell C1 instead of A1?
In case you are interested here is a one-liner macro that will also do what you want...

Code:
Sub ConcatColumnA()
  [[B][COLOR="#0000FF"]C1[/COLOR][/B]] = Join(Application.Transpose(Range("A1", Cells(Rows.Count, "A").End(xlUp))), ";")
End Sub

I highlighted in blue what you need to change if you decide to output the concatenated values to different cell from C1.
 
Upvote 0
In case you are interested here is a one-liner macro that will also do what you want...

Code:
Sub ConcatColumnA()
  [[B][COLOR=#0000FF]C1[/COLOR][/B]] = Join(Application.Transpose(Range("A1", Cells(Rows.Count, "A").End(xlUp))), ";")
End Sub

I highlighted in blue what you need to change if you decide to output the concatenated values to different cell from C1.


That was a neat line of code! :)
Thanks to you as well.
 
Upvote 0

Forum statistics

Threads
1,213,558
Messages
6,114,297
Members
448,564
Latest member
ED38

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