在日常工作中,,我們經(jīng)常會遇到大量合并的單元格,而部分合并的單元格會跨頁顯示,,也即:合并的單元格區(qū)域顯示在兩頁中,。如下圖示: 而我們最終想要的打印效果,如下: 那么,,上述效果是如何實現(xiàn)的呢,?方法如下: 步驟1:按Alt+F11快捷鍵打開工程資源管理器窗口,即VBE窗口,; 步驟2:依次單擊菜單欄上的[插入]---[模塊]選項,,在模塊1中輸入以下代碼: Sub 完整顯示合并的單元格區(qū)域() 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 模塊1代碼的截圖如下: 步驟3:返回工作表界面,因B列是合并的區(qū)域,,所以,,我們首先選擇B列數(shù)據(jù),然后在模塊1代碼窗口中,,按[執(zhí)行]按鈕,,也即達到我們想要的效果。 鳴謝:若喜歡本篇文章,,歡迎您的點贊,,評論和分享!謝謝??! |
|