|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 hjfvba666 于 2022-9-2 17:11 编辑
Sub 完整显示合并的单元格区域()
Dim P, MergeAddress As String, PageCell As Range, MergeValue
ActiveWindow.View = xlPageBreakPreview
For Each P In ActiveSheet.HPageBreaks
Set PageCell = Cells(P.Location.Row - 1, ActiveCell.Column)
If PageCell.MergeCells And Not Intersect(Cells(P.Location.Row, ActiveCell.Column), PageCell.MergeArea) Is Nothing Then
MergeAddress = PageCell.MergeArea.Address
MergeValue = PageCell.MergeArea(1).Value
PageCell.MergeArea.UnMerge
Range(Range(MergeAddress)(1), PageCell).Merge
With Range(PageCell.Offset(1, 0), Cells(Split(MergeAddress, "$")(4), ActiveCell.Column))
.Merge
.Value = MergeValue
End With
End If
Next
ActiveWindow.View = xlNormalView
End Sub
|
|