Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to display current page number in any cell of that page. | Excel Discussion (Misc queries) | |||
sheet tabs as page number and in a cell page of pages? | Excel Discussion (Misc queries) | |||
macro adding a number to a number already in a cell | Excel Programming | |||
macro adding a number to a number already in a cell | Excel Programming | |||
macro adding a number to a number already in a cell | Excel Programming |