Solved

Increment Excel cell every time a page prints

Posted on 2011-09-24
3
307 Views
Last Modified: 2012-05-12


Excel 2010 - My goal is to increment cell E9 by 1 (on my spreadsheet) for every page printed, so I wrapped the print command around a loop that increments cell E9 by 1 for every page I print. I get prompted when I run the macro for how many pages I want, then off it goes. I had to add a sleep to it as it was flooding my printers queue. Here is what I came up with:

Sub pri()
'
' pri Macro


xnum = InputBox("How many pages do you wish to print")
Range("e9").Activate
start_num = ActiveCell.Value
For i = start_num To xnum
    start_num = start_num + 1
    ActiveCell.Value = start_num
    Sleep 3000
Next i
End Sub

This macro works great, I put a 1 in cell E9, run the macro, tell it I want tp print 25 pages and off it goes, gives me 25 pages, and on each page cell E9 is one number larger. Perfect...HOWEVER, if the printer jams at say page 17, and I clear the jam and I put an 18 in cell E9, run the macro and tell it I want 8 pages, the macro will not produce any pages. I get no error, I just get nothing out of the printer. I know the jam is cleared as I can print from Word fine. The macro only seems to work if I start with a 1 in E9. If I try to start E9 with any other #, the macro produces no pages.

Any ideas experts?
thx...BobR
0
Comment
Question by:bobrossi56
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 50

Accepted Solution

by:
Ingeborg Hawighorst (Microsoft MVP / EE MVE) earned 500 total points
ID: 36592190
Hello,

If you've already printed 18 pages, then start_num will be 18. Now you want to print 8 pages, so xnum will be 8. Therefore, the for/next loop will be

for i = 18 to 8

This does not work, of course.

Since you always want to print as many pages as specified by xnum, you need to start your for/next loop at 1 and make sure that E9 will be incremented, for example like this:

xnum = InputBox("How many pages do you wish to print")
For i = 1 To xnum
    Range("E9") = Range("E9").Value + 1
    Sleep 3000
Next i

Open in new window


cheers, teylyn

0
 

Author Closing Comment

by:bobrossi56
ID: 36592206
Works like a charm....thx much...BobR
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 36592389
bobrossi56,

Glad to see you got your answer!  Just one further note: if you are ever tempted to use the Workbook's BeforePrint event for this, be very careful: that event fires for print preview, so you may not get the behavior you desire :)

Patrick
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question