Continuous printing of Excel macro control tickets

Source: Internet
Author: User

Today, the organization needs to print bills consecutively based on the data in Excel, so the following simple vba example is written.

Sheet 2 is the ticket template to be printed, and column A in sheet 3 stores the data to be printed.

You need to automatically set A cell in Sheet2 to the data of column A in Sheet3. Each time you set it, print one.

See the specific code below.

The code is as follows: Copy code

Sub continuous printing ()
'
'Continuous macro printing
'

'Define variable I
Dim I
'Cycle fifteen times
For I = 1 To 15
'Sheet3 Ai data is not empty
If Sheets ("Sheet3"). Range ("A" & I) <> "Then
'Set the A1 data in Sheet2 to the Ai data in Sheet3.
Sheets ("Sheet2"). Range ("A1"). Value = Sheets ("Sheet3"). Range ("A" & I)
'Print Sheet2
Sheets ("Sheet2"). PrintOut Copies: = 1, Collate: = True
GoTo nexti
End If
Nexti:
Next

End Sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.