Public
a
As
String
, b
As
String
, c
As
String
, d
As
String
, e
As
String
, f
As
String
, g
As
String
'定義公共變量
Public
h
As
String
, i
As
String
, j
As
String
, k
As
String
, l
As
String
, m
As
String
, LastRow
As
Integer
Sub
按鈕1_Click()
Sheets(
"sheet1"
).
Select
'選擇Sheet1工作表
LastRow = Cells(Rows.Count, 1).
End
(xlUp).Row
'求出表格內容的最后一行行號
For
x = 2
To
LastRow
'從第二行的內容開始 到最后一行
a = Cells(x, 1)
'合同編號客戶名稱 將對應行的內容讀入變量中
b = Cells(x, 2)
'合同編號 Cells(x,2)的意思是第x行第2列的單元格內容
c = Cells(x, 3)
'客戶名稱 a~m是變量,存放x行中各單元格的資料
d = Cells(x, 4)
'區域經理
e = Cells(x, 5)
'代理商
f = Cells(x, 6)
'函件單號
g = Cells(x, 7)
'是否回函
h = Cells(x, 8)
'合同總價
i = Cells(x, 9)
'到款金額
j = Cells(x, 10)
'合同余款
k = Cells(x, 11)
'截止開票金額
l = Cells(x, 12)
'開票金額
m = Cells(x, 13)
'求和項
Sheets(
"打印"
).
Select
'
Cells(1, 1).
Select
'
[J6] = a
'合同編號客戶名稱 將變量內容填入對應單元格的中
[J2] = b
'方括號中內容就是單元格名稱,如[J2]就是J2單元格
[K2] = c ’這里僅作示范,請你根據變量的內容要填入打印表格中的什么地方你自行修改
[E3] = d
[C5] = e
[E5] = f
[F5] = g
[H5] = h
[J5] = i
[D7] = j
[E7] = k
[F7] = l
[G7] = m
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=
True
, IgnorePrintAreas:=
False
'打印指定范圍內容,打印一份
Next
'處理下一行
End
Sub