excel利用vba自动合并相同单元格?

发布网友 发布时间:2022-04-21 10:32

我来回答

4个回答

热心网友 时间:2023-11-09 18:57

就你目前的截图,代码如下:

Sub test()

Dim i, irow As Integer

irow = Range("e65536").End(xlUp).Row

Application.ScreenUpdating = False

Application.DisplayAlerts = False

For i = irow To 7 Step -1

    If Cells(i, 5) <> "" And Cells(i + 1, 5) <> "" And Cells(i, 5) = Cells(i + 1, 5) Then

        Range(Cells(i + 1, 5), Cells(i, 5)).Merge

    End If

Next

Range(Cells(6, 5), Cells(irow, 5)).HorizontalAlignment = xlCenter

Range(Cells(6, 5), Cells(irow, 5)).VerticalAlignment = xlCenter 

Application.ScreenUpdating = True

Application.DisplayAlerts = True

End Sub

热心网友 时间:2023-11-09 18:57

万能处理

Excel数据重复或+空格怎样批量合并单元格

热心网友 时间:2023-11-09 18:58

Sub hb()
Dim i&, r&, rend&, c As Range
Application.DisplayAlerts = False
rend = Cells(Rows.Count, 5).End(3).Row
For i = 7 To rend
Set c = Cells(i, 5)
If c(0) <> c And c <> "" Then r = i
If c(2) <> c And c <> "" And i <> r Then
Range(Cells(r, 5), c).Merge
End If
Next
Application.DisplayAlerts = True
End Sub

热心网友 时间:2023-11-09 18:58

为什么要用VBA呢?用分类汇总、定位合并单元格不一样能解决这个问题?

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com