Fiery Greed
Fiery Greed

Reputation: 3

VBA Print Active Sheet Increment

I have a script that copies some data to a sheet and afterwards make a copy to the end of the file. The file is then repoulated with new data to be copied again to the end of the sheet. That script work fine. The only problem i have is that when i want to print out all sheets it start from the last one created instead of the first sheet. So for exemple i have 60 sheets and when they are printed it start 60,59,58...1.

What can i do to make it print from page 1 to page 60 for exemple.

Thank you.

Sub Print_All()
    For i = 4 To ActiveWorkbook.Sheets.Count
        Worksheets(i).Select
        ActiveSheet.PrintOut
    Next
    i = i + 1
End Sub

Upvotes: 0

Views: 115

Answers (2)

Vityata
Vityata

Reputation: 43585

When you use For i = 1 to N, then there is no need to go i = i + 1 and it should work:

Sub PrintAll()

    Dim i As Long
    For i = 1 To ThisWorkbook.Worksheets.Count
        Worksheets(i).PrintOut
    Next

End Sub

Furthermore, it is a good idea to avoid Select and Activate in VBA - How to avoid using Select in Excel VBA

Upvotes: 0

JohnyL
JohnyL

Reputation: 7142

For i = ActiveWorkbook.Sheets.Count To 4 Step -1

Upvotes: 1

Related Questions