hey, I need a help in creating a macro so that I can print from sheet 1 to sheet name "XYZ" as an array. In other words I want to print selected sheets as one command so that page number in the footer will automatically change.
hey, I need a help in creating a macro so that I can print from sheet 1 to sheet name "XYZ" as an array. In other words I want to print selected sheets as one command so that page number in the footer will automatically change.
Hello HardWorker,
Welcome to the Forum!
Here is macro that will loop through all the worksheets in the workbook selecting only the ones you want. The macro allows you to skip sheets. Currently the only sheet skipped is "Sheet1". You add the names of the sheets you don't selected to the code. Place the name in double quotes and separate the names with a comma.
![]()
Sub PrintSheets() Dim I As Long Dim Shts() As String For Each Sht In Sheets Select Case Sht.Name Case Is = "Sheet1" 'Do Nothing - Skip these worksheets Case Else ReDim Preserve Shts(I) Shts(I) = Sht.Name I = I + 1 End Select Next Sht Sheets(Shts).Select Sheets.PrintOut End Sub
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Hey thanks,
What if I don't want to skip any sheets between my section. For example if I have 30 sheets in my excel file and I want to print consequently from sheet 1 to sheet 25.
Hello hard worker,
This code will print sheets 1 to 25...
![]()
Sub PrintSheets() Dim I As Long Dim Shts() As String For I = 1 to 25 ReDim Preserve Shts(I) Shts(I - 1) = Sht.Name Next Sht Sheets(Shts).Select Sheets.PrintOut End Sub
Both macro are not working. The one which suppose to skip "sheet 1" is not skipping that sheet and printing all sheets. And the one which suppose to print pages 1 to 25 is giving a error. It says "invalid next control variable reference".
Hello hardworker,
Here is the corrected code for the first 25 sheets. I forgot the index variable for the sheet name.
![]()
Sub PrintSheets() Dim I As Long Dim Shts() As String For I = 1 to 25 ReDim Preserve Shts(I) Shts(I - 1) = Shts(I).Name Next Sht Sheets(Shts).Select Sheets.PrintOut End Sub
eahmed,
Welcome to the Forum, unfortunately:
Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
If I have helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
KEMelton,
As i said to eahmed above,
Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks