VBA 루프에서 시작 송장 번호를 변경하는 방법

VBA 루프에서 시작 송장 번호를 변경하는 방법

이 매크로를 구현하려고 합니다 -인쇄할 때마다 숫자 변경.

현재 일괄 인쇄 시 송장 번호 변경을 위해 매크로를 사용하려고 합니다.

***Sub PrintCopies_ActiveSheet()
Dim CopiesCount As Long
Dim copynumber As Long

CopiesCount = Application.InputBox("How many copies do you want?", Type:=1)
'Now the program wants you to input how many pages you like to print.
'You can input 100 here.

For copynumber = 1 To CopiesCount
With ActiveSheet
   .Range("E1").Value = copynumber 'I assume your invoice number is in cell E1.
   .PrintOut 'Print the sheet

End With
Next copynumber
End Sub***

그대로 작동되는데 송장번호 400번부터 일괄적으로 송장을 인쇄하고 싶습니다. 이 부분을 변경하려고 하면

For copynumber = 1 To CopiesCount

에게

For copynumber = 400 To CopiesCount

작동하지 않습니다. (이 변경 사항은 링크된 질문에서 허용되는 답변에 대한 의견에서 제안되었습니다.)

시작 송장 번호를 지정할 수 있도록 코드를 어떻게 변경합니까?

답변1

이 수정된 코드를 사용해 보세요. 송장 번호 인쇄를 위해 이 코드를 더 쉽게 사용자 정의할 수 있도록 두 개의 새로운 변수( start및 ) 를 추가했습니다 . limit이제 시작 송장 번호에 대한 두 번째 사용자 프롬프트가 표시됩니다. limit두 개의 사용자 입력으로 계산됩니다.

Sub PrintCopies_ActiveSheet()
Dim CopiesCount As Long
Dim copynumber As Long
Dim start as Variant, limit As Long

CopiesCount = Application.InputBox("How many copies do you want?", Type:=1)
'Now the program wants you to input how many pages you like to print.
'You can input 100 here.

'starting invoice number
start = Application.InputBox("Start sequence at what invoice number?", Type:=1)  

'This gives you the ability to cancel the macro by clicking Cancel.
If start = "False" Then
    Exit Sub
End If

limit = start + CopiesCount - 1   'last invoice number to print


For copynumber = start To limit
    With ActiveSheet
       .Range("E1").Value = copynumber 'I assume your invoice number is in cell E1.
       .PrintOut 'Print the sheet

    End With
Next copynumber
End Sub

관련 정보