Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default adding a page number in a cell

Ben,
That made complete sense. Easy too!

Unfortunetly I think that I didn't use the correct code. I have a one page
sheet. This sheet is the only page in this workbook. A cell "W2" that I
currently have "1334" in (this is the "order number" cell.) Everytime I print
this page I need it to add "1". So if I needed to print 6 "orders" I would
get 6 copies, numbering from 1334 to 1339 or 1335 to 1340. Sorry to start
this whole thread over again. But I figure that if I don't figure this out
now...it is going to make me lose sleep. thanks again!

Barbara

"Ben Langhammer" wrote:

You place the code in the visual basic part of the excel file. If you go to
the "Developer" tab in the ribbon, there should be an option for "Visual
Basic" (it is the left most button I think on the default ribbon for Excel
2007). Once in there, you want to put the code in the "ThisWorkbook"
section....

I hope that makes a bit of sense.

Ben

"Babs" wrote:


I have been trying to figure out, how to increase a number in a cell each
time you print it, for sometime! Now for the stupid question...Where do i
place this code?

Thanks in advance!
Barbara


"Ben Langhammer" wrote:

figured it out... Had to modify part of what you said above, but it seems to
work.

Dim ws As Worksheet
Dim lngPageNumber As Long
Dim hPgBrks As Long

lngPageNumber = 0

For Each ws In ActiveWindow.SelectedSheets
hPgBrks = 0
If ws.HPageBreaks.Count = 0 Then
hPgBrks = 1
Else
hPgBrks = ws.HPageBreaks.Count + 1
End If
lngPageNumber = lngPageNumber + hPgBrks
ws.Range("Z1").Value = lngPageNumber
Next ws

Thanks for the great posts that helped me figure it out "on my own".

Ben

"Ben Langhammer" wrote:

How could you get it to work if some worksheets are larger than 1 printed
page in size?

"Bill Renaud" wrote:


Anyway, maybe you mean to use something like the following. It puts a page
number in cell I7 on each of the selected worksheets starting at (page) 1.
This assumes that each worksheet is only 1 printed page in size.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim ws As Worksheet
Dim lngPageNumber As Long

lngPageNumber = 0

For Each ws In ActiveWindow.SelectedSheets
lngPageNumber = lngPageNumber + 1
ws.Range("I7").Value = lngPageNumber
Next ws
End Sub

--
Regards,
Bill Renaud

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to display current page number in any cell of that page. Laljeet Excel Discussion (Misc queries) 8 February 2nd 08 01:31 AM
sheet tabs as page number and in a cell page of pages? [email protected] Excel Discussion (Misc queries) 0 November 22nd 05 02:43 PM
macro adding a number to a number already in a cell Tom Ogilvy Excel Programming 0 October 18th 03 04:34 PM
macro adding a number to a number already in a cell Don Guillett[_4_] Excel Programming 0 October 17th 03 05:21 PM
macro adding a number to a number already in a cell Ron de Bruin Excel Programming 0 October 17th 03 04:59 PM


All times are GMT +1. The time now is 03:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"