Quickest way to concatenate multiple columns on multiple rows

Philippe.T

Board Regular
Joined
Jan 30, 2012
Messages
94
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hello all,

I've got thousands of rows for which I need to concatenate multiple columns like in below example.
In belwo example the columns B,C and D are concatenated in column E

a.png


My question is: what is the quickest way?
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Depending on your version, you could use TEXTJOIN
 
Upvote 0
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Depending on your version, you could use TEXTJOIN
Hello Fluff,

I updated my account details.
Note that I am looking for a VBA solution and not for a formula
 
Upvote 0
Roughly how many rows is thousands?
 
Upvote 0
Ok, how about
VBA Code:
Sub PhilippeT()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long
   
   Ary = Range("B2:D" & Range("B" & Rows.Count).End(xlUp).Row)
   ReDim Nary(1 To UBound(Ary), 1 To 1)
   
   For r = 1 To UBound(Ary)
      Nary(r, 1) = Ary(r, 1) & ";" & Ary(r, 2) & ";" & Ary(r, 3)
   Next r
   Range("E2").Resize(r - 1).Value = Nary
End Sub
 
Upvote 0
Ok, how about
VBA Code:
Sub PhilippeT()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long
  
   Ary = Range("B2:D" & Range("B" & Rows.Count).End(xlUp).Row)
   ReDim Nary(1 To UBound(Ary), 1 To 1)
  
   For r = 1 To UBound(Ary)
      Nary(r, 1) = Ary(r, 1) & ";" & Ary(r, 2) & ";" & Ary(r, 3)
   Next r
   Range("E2").Resize(r - 1).Value = Nary
End Sub
Many Thanks Fluff. This works great!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Playing around with this I realized that on 400k+ rows, arraylists are slow. Dictionaries are better, but just a good old array like Fluff used was lightning quick.

This might shave off a millisecond or two, but for all intents and purposes, they are the same speed. Fun to play with though.

VBA Code:
Sub COMBIX()
Dim a As Range:         Set a = Range("B2:B" & Range("B" & Rows.Count).End(xlUp).Row)

a.Offset(, 3).Value = Evaluate(Replace(Replace(Replace("=@&"";""&*&"";""&#", "@", a.Address), "*", a.Offset(, 1).Address), "#", a.Offset(, 2).Address))

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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