- 帖子
- 552
- 主題
- 3
- 精華
- 0
- 積分
- 578
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- office 2010
- 閱讀權限
- 50
- 性別
- 男
- 註冊時間
- 2015-2-8
- 最後登錄
- 2024-7-9
  
|
12#
發表於 2016-4-26 22:17
| 只看該作者
回復 11# starry1314
Option Explicit
Sub 巨集1()
Dim c As Range, firstAddress$, myColumn%
With Sheets("工作表1")
Set c = .Rows(3).Find("P.P", LookIn:=xlValues) '尋求第一個目標物件
If Not c Is Nothing Then '如果c物件不是為Nothing時,執行
firstAddress = c.Address '記錄找到的第一個位置
myColumn = 1 '設定A欄
Do
'.Range(.Cells(2, myColumn), .Cells(Rows.Count, c.Column).End(xlUp)).Name = "Print_Area" '
.Range(.Cells(Rows.Count, myColumn).End(xlUp), Cells(2, c.Column)).Name = "Print_Area" '設定列印範圍,以設定範圍來說,例如:"A1:C5"和"A5:C1"是一樣的意思
'只不過A欄可以找到最後一列,所以要用後者來設定範圍
.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False '列印
Set c = .Rows(3).FindNext(c) '尋找下一個目標物
myColumn = myColumn + 19 '下一個個位置為T欄...再來是AM欄,依此類推
Loop While Not c Is Nothing And c.Address <> firstAddress '當c的位址和第一個位址相同時,跳出迴圈
End If
End With
End Sub |
|