ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Formula question (https://www.excelbanter.com/excel-worksheet-functions/205029-formula-question.html)

iarnold

Formula question
 
I am trying to find a formula that will advance the numerical value of a cell
by 1 when I print a document - its for an invoice template, so that the
invoice number advances. Because I have a number of worksheets in this
workbook, I would want them all to advance by 1 when I print.

Help!

Sean Timmons

Formula question
 
For i = 1 to 20
For j = 1 to 20
Sheets("Sheet"&j).Select
Range("G40").Value = i
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1,
Copies:=1,
Collate_:=True
Next j
Next i

Will spin you through 20 sheets 20 times, changing the value in G40 of each
cell to the new page #. This assumes your pages are labelled "Sheet1",
"Sheet2", "Sheet3", etc.

"iarnold" wrote:

I am trying to find a formula that will advance the numerical value of a cell
by 1 when I print a document - its for an invoice template, so that the
invoice number advances. Because I have a number of worksheets in this
workbook, I would want them all to advance by 1 when I print.

Help!


Rick Rothstein

Formula question
 
You can do that using VBA event code. Right click the icon immediately to
the left of the File item on Excel's menu bar and select View Code from the
pop up menu that appears. Copy/Paste this code into the code window that
appeared (it is the code window for ThisWorkbook)...

Private Sub Workbook_BeforePrint(Cancel As Boolean)
With Worksheets("Sheet1").Range("A1")
.Value = .Value + 1
End With
End Sub

Change the Sheet1 and A1 references in the Worksheets and Range function
calls in the With statement to the worksheet name and cell address where you
want this counter placed.

--
Rick (MVP - Excel)


"iarnold" wrote in message
...
I am trying to find a formula that will advance the numerical value of a
cell
by 1 when I print a document - its for an invoice template, so that the
invoice number advances. Because I have a number of worksheets in this
workbook, I would want them all to advance by 1 when I print.

Help!



iarnold

Formula question
 
Thanks

Do I paste this formula in the particular cell or somewhere else?

"Sean Timmons" wrote:

For i = 1 to 20
For j = 1 to 20
Sheets("Sheet"&j).Select
Range("G40").Value = i
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1,
Copies:=1,
Collate_:=True
Next j
Next i

Will spin you through 20 sheets 20 times, changing the value in G40 of each
cell to the new page #. This assumes your pages are labelled "Sheet1",
"Sheet2", "Sheet3", etc.

"iarnold" wrote:

I am trying to find a formula that will advance the numerical value of a cell
by 1 when I print a document - its for an invoice template, so that the
invoice number advances. Because I have a number of worksheets in this
workbook, I would want them all to advance by 1 when I print.

Help!


Sean Timmons

Formula question
 
Well, that's cleaner than mine!

"Rick Rothstein" wrote:

You can do that using VBA event code. Right click the icon immediately to
the left of the File item on Excel's menu bar and select View Code from the
pop up menu that appears. Copy/Paste this code into the code window that
appeared (it is the code window for ThisWorkbook)...

Private Sub Workbook_BeforePrint(Cancel As Boolean)
With Worksheets("Sheet1").Range("A1")
.Value = .Value + 1
End With
End Sub

Change the Sheet1 and A1 references in the Worksheets and Range function
calls in the With statement to the worksheet name and cell address where you
want this counter placed.

--
Rick (MVP - Excel)


"iarnold" wrote in message
...
I am trying to find a formula that will advance the numerical value of a
cell
by 1 when I print a document - its for an invoice template, so that the
invoice number advances. Because I have a number of worksheets in this
workbook, I would want them all to advance by 1 when I print.

Help!




Sean Timmons

Formula question
 
Please see Rick Rothstein's post below. Much cleaner than mine, really.

You'd right-click on the tab name and click View Code, as he explans. :-)

"iarnold" wrote:

Thanks

Do I paste this formula in the particular cell or somewhere else?

"Sean Timmons" wrote:

For i = 1 to 20
For j = 1 to 20
Sheets("Sheet"&j).Select
Range("G40").Value = i
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1,
Copies:=1,
Collate_:=True
Next j
Next i

Will spin you through 20 sheets 20 times, changing the value in G40 of each
cell to the new page #. This assumes your pages are labelled "Sheet1",
"Sheet2", "Sheet3", etc.

"iarnold" wrote:

I am trying to find a formula that will advance the numerical value of a cell
by 1 when I print a document - its for an invoice template, so that the
invoice number advances. Because I have a number of worksheets in this
workbook, I would want them all to advance by 1 when I print.

Help!


Rick Rothstein

Formula question
 
You'd right-click on the tab name and click View Code, as he explans. :-)

Not on the tab name; rather, on the icon next to (on the left of) the File
item on the menu bar... then click View Code. Doing it that way takes you
directly to the ThisWorkbook code window.

--
Rick (MVP - Excel)


"Sean Timmons" wrote in message
...
Please see Rick Rothstein's post below. Much cleaner than mine, really.

You'd right-click on the tab name and click View Code, as he explans. :-)

"iarnold" wrote:

Thanks

Do I paste this formula in the particular cell or somewhere else?

"Sean Timmons" wrote:

For i = 1 to 20
For j = 1 to 20
Sheets("Sheet"&j).Select
Range("G40").Value = i
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1,
Copies:=1,
Collate_:=True
Next j
Next i

Will spin you through 20 sheets 20 times, changing the value in G40 of
each
cell to the new page #. This assumes your pages are labelled "Sheet1",
"Sheet2", "Sheet3", etc.

"iarnold" wrote:

I am trying to find a formula that will advance the numerical value
of a cell
by 1 when I print a document - its for an invoice template, so that
the
invoice number advances. Because I have a number of worksheets in
this
workbook, I would want them all to advance by 1 when I print.

Help!




All times are GMT +1. The time now is 08:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com