我创建了 1/4 信纸大小的收据,并在一个工作表中复制了 4 次(以节省纸张),并希望从 001 连续打印到 100。每张收据都应有一个唯一的序列号 001,002...100..
我怎样才能在 4 个不同的单元格中输入连续的数字,比如 A1、C1、E1 和 G1 是我的单元格,编号分别为 001、002、003、004,并在每次打印后增加每个数字?
我还需要能够指定起始数字。
我在网上发现了这一点,所以也许这是一个开始:
Sub IncrementPrint()
Dim xCount As Variant
Dim xScreen As Boolean
Dim I As Long
On Error Resume Next
LInput:
xCount = Application.InputBox("Please enter the number of copies you want to print:", "Title")
If TypeName(xCount) = "Boolean" Then Exit Sub
If (xCount = "") Or (Not IsNumeric(xCount)) Or (xCount < 1) Then
MsgBox "error entered, please enter again", vbInformation, "Title"
GoTo LInput
Else
xScreen = Application.ScreenUpdating
Application.ScreenUpdating = False
For I = 1 To xCount
ActiveSheet.Range("A1").Value = " Company-00" & I
ActiveSheet.PrintOut
Next
ActiveSheet.Range("A1").ClearContents
Application.ScreenUpdating = xScreen
End If
End Sub
答案1
用这个
Option Explicit
Public Sub IncrementPrint()
Dim resp As Variant, scr As Boolean, i As Long, j As Long
On Error Resume Next
resp = Application.InputBox(Prompt:="Please enter the number of copies to print:", _
Title:="Select Total Print Copies", Type:=1)
On Error GoTo 0
If resp = False Then Exit Sub
If resp < 1 Or resp > 100 Then
MsgBox "Invalid number: " & resp & " (Enter 1 to 100)", vbExclamation, "Try Again"
Exit Sub
End If
scr = Application.ScreenUpdating
Application.ScreenUpdating = False
j = 0
For i = 1 To resp
ActiveSheet.Range("A1").Value2 = " Company-00" & i + 0 + j
ActiveSheet.Range("C1").Value2 = " Company-00" & i + 1 + j
ActiveSheet.Range("E1").Value2 = " Company-00" & i + 2 + j
ActiveSheet.Range("G1").Value2 = " Company-00" & i + 3 + j
ActiveSheet.PrintOut
j = j + 3
Next i
ActiveSheet.Range("A1,C1,E1,G1").ClearContents
Application.ScreenUpdating = scr
End Sub