excel VBA快速合并相同内容的单元格

 时间:2024-10-12 05:08:46

1、添加以下代码到VBA编辑器中:=============屏顿幂垂=====华丽的分割线-此线不要复制===========Sub 合矣喾动痞并相同内容单元格()Dim sheet1 As Worksheet, mSheet As WorksheetDim index!, sheetIndex!, temp, startindex!, index1!, index2!, targetIndex!, sheetCount!, endL!targetIndex = 2 '要合并的单元格所在列startindex = 1 '从第几行开始判断是否合并单元格Set sheet1 = ActiveWorkbook.ActiveSheet '当前工作表index1 = 1index2 = 1endL = 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 IfApplication.DisplayAlerts = TrueEnd Sub==================华丽的分割线-此线不要复制===========

excel VBA快速合并相同内容的单元格

2、根据自己的需求修改代码中两处位置的参数值:targetIndex = 2 '要合并的单元格所在列startindex = 1 '从第几行开始判断是否合并单元格按 F5 运行,1秒钟完成合并操作

excel VBA快速合并相同内容的单元格

3、不懂得如何运行VBA的请参照:

  • Excel表中VBA的程序如何使用VLookup查找函数
  • 怎样使用VBA计算已用行列数?
  • Excel如何VBA代码排序?
  • 如何用vba在excel中将数值相同的两项放在同一行
  • 怎样使用VBA向列表框追加数据?
  • 热门搜索
    致敬英雄手抄报图片 校园手抄报模板 元宵节手抄报图片 中国梦手抄报图片 反邪教手抄报内容 红领巾手抄报 疫情手抄报内容 自我介绍手抄报 感恩母亲手抄报 禁毒防艾手抄报