Concatenate Range macro

When you want to merge values from multiple cells into a single cell, the usual solution is to use the CONCAT or CONCATENATE function, or the ‘&’ (ampersand) symbol, to join cell values in a formula.

Joining cell values with a space in between using the CONCATENATE function
Joining cell values with a space in between using the CONCATENATE function

This is perfect for setting up arrays of formulas to re-use with changing cell data.

But there are times when you might want to be able to instantly merge Excel cell data on the spot, without the fuss of typing in formulas and then clicking copy. 

You can add a macro button to your Excel Quick Access Toolbar, or to the Excel Ribbon to do this for you, using the VBA code below. This macro will merge a selected range of cells and store the result to the clipboard. So it’s ready to paste directly where you need it.

Tips

#1 You can select the order in which the cells will be joined, by simply selecting the cells (left click) while holding down the CTRL key. Then click the macro button to join the selection in your cliboard ready to paste.

#2 This code joins the cell values with a space in between. You can delete the space or replace it with any another symbol such as a hypen, comma or period if you like.

VBA Macro Code

Sub range_concatenate()
Dim rng As Range 'the selected range
Dim thiscell As Range 'next cell in the selection
Dim joined 'concatenated string
joined = ""
Dim clip_data As DataObject
Set clip_data = New DataObject
Set rng = Selection
For Each thiscell In Selection
'you can replace the space in quotes with another symbol or remove it
joined = joined & " " & thiscell
Next
'append clipboard to end of selected cell contents
clip_data.SetText joined
clip_data.PutInClipboard
'optional message:
message = MsgBox("Copied to clipboard: " & joined, vbOKCancel, "Concatenate range macro")
Select Case message
Case vbCancel
End
End Select
End Sub

Learn how to add macro buttons to your Quick Access Toolbar in Excel

To learn how to enable macros to run, and how to save the above VBA macro code to your Excel, please download my e-book on Amazon, Making the Most of the Quick Access Toolbar in Excel, for step by step directions:

Making The Most Of The Quick Access Toolbar In Excel
Scroll to Top