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.
- On the Developer Tab, select the Visual Basic option under the Code section.
- 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.
- You have to open the sheet containing the data. On the Developer Tab, choose the Macros option in the Code section.
- You need to make sure that your macro is selected and click the Run button.
- You need to select the input range and click the OK button.
- Now, you have to select the destination cell to place the result.
- Finally, you will get the result as shown in the below image.
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!
Top comments (0)