|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 念念鱼草 于 2022-1-7 17:50 编辑
我前面5列都是合并单元格,在打印预览的时候展示不全,我需要每一列合并单元格都展示完全。下面的VBN只能展示1列
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(Cells(1, 1), Cells(5, 10)).Select
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
然后选中第一列,点运行即可
|
|