Solved

Increment Excel cell every time a page prints

Posted on 2011-09-24
3
308 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 93

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

635 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