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.
![]()
Please Login or Register to view this content.
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...
![]()
Please Login or Register to view this content.
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.
![]()
Please Login or Register to view this content.
sorry to say but it is still not working.
Hello hardworker,
This has not been my week for coding. Place this code in its own Module and mix any other code with it. The reason is it sets the beginning array index to 1, normally it is zero. This is necessary because the Sheets collection starts at one .
![]()
Please Login or Register to view this content.
Or you could go this way (See attached)
You'll have to add the page number in the footer yet though.
HTH
John
Code mention below is working when I am trying to print sheets from page 1 to XXX but if I am trying to start my print command from page 4. Then it is not working. Can you suggest why?and how I can fix that?
![]()
Please Login or Register to view this content.
Last edited by shg; 03-23-2009 at 01:19 PM. Reason: code tags
Please edit your post to add code tags.
Entia non sunt multiplicanda sine necessitate
Any help on my last post.
Hey I asked this question couple of days back but didn't get any reply. Can anybody help me.
Thanks in advance....
Code mention below is working when I am trying to print sheets from page 1 to XXX but if I am trying to start my print command from page 4. Then it is not working. Can you suggest why?and how I can fix that?
![]()
Please Login or Register to view this content.
Hello hardworker,
You need to change the starting index of the For Next from 1 to 4'
![]()
Please Login or Register to view this content.
Itried that but it din't work. Can you test yourself and let me know?
Hello hardworker,
Please be more specific about the problem. Are you getting an error? If so, what is the error number and description. Is it printing the wrong sheets? If so, which sheets are being printed?
Hello Hardworker,
I revised the macro and this works on my machine with no errors. The Sheets Array has to start at 1 (one). To build the array correctly a separate counter must be used. In the code "N" is the independent counter for the array. The names of the worksheets, starting with the fourth worksheet, are loaded into the array starting at position 1 (one).
![]()
Please Login or Register to view this content.
I want to use an excel macro to print only those sheets that are visible (There may be sheets which are hidden). When I use the code "Sheets(Array(sheet 1, sheet 2,...,sheet n).Select", it prints only these sheets and if any of these sheet is not visible it returns with error. Kindly help me.
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]
How do I print only a grouped set of sheets (say -test1, test2, test3, test4, test5) but only the page that I select...there are 10 pages on each sheet.If I want page 1 of each or page 10 of each...
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