其他分享
首页 > 其他分享> > Excel小技巧:合并单元格且不丢失数据

Excel小技巧:合并单元格且不丢失数据

作者:互联网

方法:使用VBA

可以使用下面的代码合并所选单元格:

Sub MergeCells()

'连接所选单元格中的所有内容并将其放入最上方单元格

'然后合并所有单元格

Dim strOutput As String

Dim rng As Range

Const delim = " "

On Error Resume Next

For Each rng In Selection

strOutput = strOutput & rng.Value & delim

Next rng

With Selection

.Clear

.Cells(1).Value = strOutput

.Merge

.HorizontalAlignment = xlGeneral

.VerticalAlignment = xlCenter

.WrapText = True

End With

End Sub

标签:End,Sub,Excel,单元格,rng,Next,丢失,strOutput
来源: https://blog.csdn.net/u014312384/article/details/122662943