0

我希望每次单击时将单元格值更新为另一张表中的下一个单元格值,然后打印该值。

Sub SerPrint()

i = 1

'when button click it change to `c3 c4 c5 and C......
' until the end of table
Sheet1.Range("n7").Value = Sheet2.Range("C"2 + i )
'like Value in cell N7 from sheet1 have value from c2 Sheet2 then
' after i click it change to c3,c4,c5,c....

Sheet1.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
' then print out

End Sub
4

2 回答 2

2

每次执行子程序时,您都需要添加公共变量来控制行的偏移量。

将此行添加到项目中任何模块的顶部

Public iOffset as Long

你的潜艇看起来像这样:

Sub SerPrint()

'let's start with value of C2 from Sheet2
Sheet1.Range("n7").Value = Sheet2.Range("C2").Offset(iOffset, 0)

Sheet1.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
' then print out

'here we increment our public variable for next click to make C3, C4...
iOffset = iOffset + 1


End Sub
于 2013-07-10T06:51:43.140 回答
1

以你的风格..

Sheet1.Range("n7").Value = Sheet2.Range("C" & format(2 + i) )

如果你想使用 Offset ..

Sheet1.Range("n7").Value = Sheet2.Range("C2").Offset(i,0)   
于 2013-07-10T07:00:28.580 回答