Add 1 to a number each time you print

J

Jason1

I have a form that I have created that has a Shipper # in the top right
hand corner, each time someone prints the page I need this to
automatically add 1 to the number. People on this website have helped
me out numerous times, and I know you will be able to help me out with
this..
 
J

Jim Thomlinson

Add the following code to ThisWorkbook (Right click the excel icon next to
file on the menu and select view code). You will need to change the sheet
name and the range being updated (A1). This code should work for you so long
as you are not doing print previews (which will also fire off this code)...

Private Sub Workbook_BeforePrint(Cancel As Boolean)
if activesheet.name = "Sheet1" then _
activesheet.range("A1").value = activesheet.range("A1").value + 1
End Sub
 
J

Johnny

Maybe something like this:

(air code)

This should be in the ThisWorkbook class module in the editor:

Private Sub Workbook_BeforePrint(Cancel as Boolean)
Dim r as Range

'Set up reference to range
Set r = Range("YourCellHere")

With r
'Add one to the value already in the cell
.Cells(1,1).Value = .Cells(1,1).Value + 1
End with

'Clean up
Set r = Nothing
End Sub

HTH,
Johnny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top