返回列表 上一主題 發帖

[發問] 關於不固定欄 自動列印至最後一筆資料

回復 3# lpk187


    實在太感謝了,find 真好用

TOP

回復 1# starry1314


    也可以這樣!
  1. Option Explicit

  2. Sub 巨集1()
  3.     Dim c As Range
  4.     With Sheets("工作表1")
  5.         Set c = .Rows(3).Find("P.P", , , , , 1) '往後尋找
  6.         .PageSetup.PrintArea = .Range(.Cells(Rows.Count, 1).End(xlUp), Cells(2, c.Column)).Address '設定列印範圍
  7.         .PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False '列印
  8.         Set c = Nothing
  9.         Set c = .Rows(3).Find("P.P", , , , , 2) '往前尋找
  10.         .PageSetup.PrintArea = .Range(.Cells(Rows.Count, 1).End(xlUp), Cells(2, c.Column)).Address '設定列印範圍
  11.         .PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False '列印
  12.         Set c = Nothing
  13.     End With
  14. End Sub
複製代碼

TOP

回復 1# starry1314


    給你參考,我的做法
  1. Option Explicit

  2. Sub 巨集1()
  3.     Dim c As Range
  4.     With Sheets("工作表1")
  5.         Set c = .Rows(3).Find("P.P", , , , , 1)
  6.         .PageSetup.PrintArea = "$A$2:" & .Cells(Rows.Count, c.Column).End(xlUp).Address '設定列印範圍
  7.         .PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False '列印
  8.         Set c = Nothing
  9.         Set c = .Rows(3).Find("P.P", , , , , 2)
  10.         .PageSetup.PrintArea = "$T$2:" & .Cells(Rows.Count, c.Column).End(xlUp).Address
  11.         .PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False '列印
  12.         Set c = Nothing
  13.     End With
  14. End Sub
複製代碼

TOP

        靜思自在 : 【時間如鑽石】時間對一個有智慧的人而言,就如鑽石般珍貴;但對愚人來說,卻像是一把泥土,一點價值也沒有。
返回列表 上一主題