While working with Excel spreadsheets, you've likely encountered the need to merge multiple cells to create a more visually appealing and organized layout. However, traditionally, merging cells in Excel would result in losing data or retaining only the value of the first cell. If you want to merge multiple cells into one in Excel without losing any data, Mytour can assist you in achieving this through a few VBA operations.
Merging multiple cells into one in Excel without losing data
Step 1: Select the data cells you want to merge into one comprehensive cell.
Step 2: Next, click on the View tab -> Macro (on Excel 2007, 2010, 2013, 2016) or the Tools tab ->
Step 3: In the Macro window, enter the Macro name as the name of the program to execute the action of merging multiple cells into one in Excel without losing data, then click Create.
Note: Enter the name without accents.
Step 4: You will be redirected to the VBA window. Here, you'll copy and paste the following code snippet between the 'Sub' and 'End Sub' sections:
Dim Cll As Range, Temp As String
On Error Resume Next
If Selection.MergeCells = False Then
For Each Cll In Selection
If Cll <> '' Then Temp = Temp + Cll.Text + _
' '
Next Cll
Selection.Merge
Selection.Value = Left(Temp, Len(Temp) - 1)
Else
Selection.UnMerge
End If
Selection.HorizontalAlignment = xlCenter
Selection.VerticalAlignment = xlCenter
After copying, you'll have the following line of code to merge multiple cells into one cell without losing data in Excel:
Step 5: To execute the command to merge multiple cells in Excel without losing data, click on the Play button, shaped like a triangle, on the toolbar.
Step 6: If the program displays a message like the one below, continue by clicking OK.
Afterward, return to your Excel file and you'll see that the data from those cells has been merged into one cell seamlessly without losing any data from the original cells.
Above, Mytour has guided you on how to merge multiple cells into one in Excel without losing data. Additionally, you can explore how to swap the positions of two columns in Excel, rearrange columns to better interact with Excel spreadsheets.
Centering cells in Excel or Word is crucial for presenting documents and data. While it may seem simple, not everyone can do it. Refer to how to center a cell in Word, Excel here.