Concatenate Range of Cells

marcusmark

Board Regular
Joined
Nov 17, 2014
Messages
98
Hi,
Is there a vba code to concatenate range of cells?
The range will start with CellA1 and can have up CellA1000 but this is not definite as it can be lower than that.
Concatenation need ";" as its separator.
Sample is when I have Apple in CellA1, Mango in CellA2, Orange in CellA3....the value in CellC1 will be Apple;Mango;Orange
Thanks!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Maybe this UNTESTED
Code:
Sub MM1()
Dim lr As Long, r As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
    For r = 1 To lr
        If Range("C1").Value = "" Then
            Range("C1").Value = Range("A" & r).Value + ";"
            Else
            Range("C1").Value = Range("C1").Value + Range("A" & r).Value + ";"
        End If
    Next r
End Sub
 
Upvote 0
Hi Michael,
It got an error because of "+". I changed it to "&" instead and it now works perfectly fine. Thanks a lot! :)
 
Upvote 0
You can also do what you want without using a loop, all it takes is one line of code...
Code:
Sub ConcatenateA1ToLastValueInColumnA()
  [C1] = Join(Application.Transpose(Range("A1", Cells(Rows.Count, "A").End(xlUp))), ";")
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,067
Messages
6,122,949
Members
449,095
Latest member
nmaske

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