When you use Excel to organize the table data, you want to be able to automatically merge the contents of all the cells in the selected area, but the Excel software comes with the merge function does not meet this requirement, what should do?
We can write a "macro" that subtly saves data in all cells in a selection, iterates through a variable, and then prints the result to the merged cell.
The code is as follows:
Sub Merge Cells ()
' Turn off screen updates and warning tips
application.screenupdating = False
Application.DisplayAlerts = False
Dim i%
' Cycle the cell data in the selected range and merge it into Strtotal
For i = 1 to Selection.count
Strtotal = strtotal & Selection.Cells (i)
Next
' Set the selection format
With Selection
. MergeCells = True
. HorizontalAlignment = Xlcenter
. VerticalAlignment = Xlcenter
. Value = "' & Strtotal ' before merging data plus ' number
End With
' Restore screen updates and warning tips
Application.DisplayAlerts = True
application.screenupdating = True
End Sub
Assign the above macro to a custom toolbar button. Then we can test the results, such as in a few nonadjacent cells in a sequence of different data input (can be text, letters or numbers), and finally select all the data range, click the button that you have just customized, you can see the effect of the merge.