|
- Sub 解除合并单元格()
- Dim b%, rng As Range
- last = ActiveSheet.Range("D" & Rows.Count).End(xlUp).Row
- ' For Each rng In Selection
- For Each rng In Range("D5:F" & last)
- b = rng.MergeArea.Count
- rng.UnMerge
- rng.Resize(b) = rng
- Next
- Call test6
- End Sub
- Sub test6()
- last = ActiveSheet.Range("D" & Rows.Count).End(xlUp).Row
- ' Range("A5:F" & last).UnMerge
- With ActiveSheet.Sort
- With .SortFields
- .Clear
- .Add2 Key:=Range("E5:E" & last), Order:=xlDescending
- .Add2 Key:=Range("F5:F" & last), Order:=xlDescending
- .Add2 Key:=Range("P5:P" & last), Order:=xlDescending
- End With
- .SetRange Range("E5:U" & last)
- .Apply
- End With
- Call 合并相同单元格1
- Call 合并相同单元格2
- Call 合并相同单元格3
- End Sub
- Sub 合并相同单元格1()
- Dim merng As Range
- Dim r
- r = "D"
- Application.DisplayAlerts = False
- Set merng = Range(r & "5")
- For i = 5 To [D65536].End(xlUp).Row
- If Range(r & i) = Range(r & i - 1) Then
- Set merng = merng.Resize(merng.Count + 1, 1)
- Else
- merng.Merge
- Set merng = Range(r & i)
- End If
- Next
- merng.Merge
- Application.DisplayAlerts = True
- End Sub
- Sub 合并相同单元格2()
- Dim merng As Range
- Dim r
- r = "E"
- Application.DisplayAlerts = False
- Set merng = Range(r & "5")
- For i = 5 To [D65536].End(xlUp).Row + 1
- If Range(r & i) = Range(r & i - 1) Then
- Set merng = merng.Resize(merng.Count + 1, 1)
- Else
- merng.Merge
- Set merng = Range(r & i)
- End If
- Next
- merng.Merge
- Application.DisplayAlerts = True
- End Sub
- Sub 合并相同单元格3()
- Dim merng As Range
- Dim r
- r = "F"
- Application.DisplayAlerts = False
- Set merng = Range(r & "5")
- For i = 5 To [D65536].End(xlUp).Row + 1
- If Range(r & i) = Range(r & i - 1) Then
- Set merng = merng.Resize(merng.Count + 1, 1)
- Else
- merng.Merge
- Set merng = Range(r & i)
- End If
- Next
- merng.Merge
- Application.DisplayAlerts = True
- End Sub
复制代码
代码抄论坛老师,我不懂,只能组装式,但不知道对不对,希望老师能合并代码
想学多列同时循环合并,怎么弄。
|
评分
-
1
查看全部评分
-
|