DEV Community

Andrews
Andrews

Posted on • Originally published at geekexcel.com on

Merge Multiple Cells into One Cell using Macros (VBA) in Excel 365!!

If you want to merge multiple cells into one without losing data, what will you do? Here, we come up with some simple steps to merge multiple cells into one cell using Macros & VBA in Excel Office 365. Let’s get into this article and learn the clear-cut steps to finish this task quickly.

Merge Multiple Cells into One Cell using Macros:

To combine multiple cells into a single cell in the Excel worksheet, do as follows.

  • First, you need to open the workbook where you want to merge cells.
  • Here, we have shown the example data range from A1:B2. We are going to combine these steps with the help of macros.

Example range
Example range

  • On the Developer Tab, select the Visual Basic option under the Code section.

Select Visual Basic option
Select the Visual Basic option

  • Then you need to copy and paste the code given below.

VBA code to combine multiple cells into one using Macros

Sub MergeCells()

Dim xJoinRange As Range

Dim xDestination As Range

Set xJoinRange = Application.InputBox(prompt:=”Highlight source cells to merge”, Type:=8)

Set xDestination = Application.InputBox(prompt:=”Highlight destination cell”, Type:=8)

temp = “”

For Each Rng In xJoinRange

temp = temp & Rng.Value & ” “

Next

xDestination.Value = temp

End Sub

  • You need to save the code by selecting it. Then close the window.

Save the code
Save the code

  • You have to open the sheet containing the data. On the Developer Tab, choose the Macros option in the Code section.

Choose the Macros option
Choose the Macros option

  • You need to make sure that your macro is selected and click the Run button.

Click the Run button
Click the Run button

  • You need to select the input range and click the OK button.

Input dialog box
Input dialog box

  • Now, you have to select the destination cell to place the result.

Click OK button
Click OK button

  • Finally, you will get the result as shown in the below image.

Output
Output

Wrap-Up:

In this article, we have illustrated the clear-cut steps to merge multiple cells into one cell using Macros & VBA in Excel Office 365. Leave your feedback in the below comment section. Thanks for visiting Geek Excel. Keep Learning!

Keep Reading:

Top comments (0)