0

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
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73

2 Answers2

1
For i = ActiveWorkbook.Sheets.Count To 4 Step -1
JohnyL
  • 6,894
  • 3
  • 22
  • 41
  • Hm his code aside, you read the question text differently than me. I read that it is printing in reverse by default and he wants to print 1, 2, 3, ... 58, 59, 60. **Quote:** _problem ... is ... it start from the last one created instead of the first sheet_ – Mark Balhoff Jun 23 '19 at 20:08
  • @MarkBalhoff Per OP: *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__* – JohnyL Jun 23 '19 at 20:10
  • Thank you very much JohnyL it works perfectly. Have a great day ! :) – Fiery Greed Jun 24 '19 at 05:37
0

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

Vityata
  • 42,633
  • 8
  • 55
  • 100