发布网友 发布时间:2022-02-25 12:10
共1个回答
热心网友 时间:2022-02-25 13:39
用VBA可以实现,网页链接
==================华丽的分割线-此线不要复制===========
Sub 合并相同内容单元格()
Dim sheet1 As Worksheet, mSheet As Worksheet
Dim index!, sheetIndex!, temp, startindex!, index1!, index2!, targetIndex!, sheetCount!, endL!
targetIndex = 2 '要合并的单元格所在列
startindex = 1 '从第几行开始判断是否合并单元格
Set sheet1 = ActiveWorkbook.ActiveSheet '当前工作表
index1 = 1
index2 = 1
endL = sheet1.UsedRange.Rows.count '获取表的总行数
Application.DisplayAlerts = False
'endL = zuSheet.Range("a1000").End(xlUp).Row '获取表某一列有数据的总行数
For index = startindex To endL '工作表构件列表循环
If temp = sheet1.Cells(index, targetIndex) Then
index2 = index
Else
If index1 <> index2 Then
sheet1.Range(sheet1.Cells(index1, targetIndex), sheet1.Cells(index2, targetIndex)).Merge '合并
End If
index1 = index
index2 = index
End If
temp = sheet1.Cells(index, targetIndex)
Next
If index1 <> index2 Then
sheet1.Range(sheet1.Cells(index1, targetIndex), sheet1.Cells(index2, targetIndex)).Merge '合并
End If
Application.DisplayAlerts = True
End Sub
==================华丽的分割线-此线不要复制===========