Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Help please I cannot get an answer to this question

Hi
I have a macro which uses code to populate certain cells in a document and
then prints this page.
I would like to be able to use code to generate a sequential whole number
each time the macro is run and place this number in a cell on the document to
be printed. Thus whenever the document is printed it is numbered and this
number increases by one each time.

How can this be done please?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Help please I cannot get an answer to this question

Hi Alan,

I hope I understood your question (but I am not sure).

Supposing that you store this sequential number in sheet1, cell A1, you
can use following code:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
worksheets("sheet2").range("a1").value=worksheets( "sheet2").range("a1").value+1
End Sub

adjust the code to your needs.

It will add 1 to value of cell A1 on sheet1 and application will
continue showing the print dialog. What should happen if user cancels
it?

Regards,
Ivan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Help please I cannot get an answer to this question

Sorry, I mistyped, in the code "sheet2" should be "sheet1" to
correspond with the description.

Ivan

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default Help please I cannot get an answer to this question

In the immediate window of the VBE, add a name e.g. MyCounter, thus:

Application.ActiveWorkbook.Names.Add "MyCounter","1"

Save the workbook.

Application.ActiveWorkbook.Save

In your macro, to query the current value:
Evaluate(Application.ActiveWorkbook.Names.Item("My Counter").Value)

To upadate the value:
Application.ActiveWorkbook.Names.Item("MyCounter") .Value = 100

Save the workbook to ensure counter is updated:

Application.ActiveWorkbook.Save

"Alan M" wrote:

Hi
I have a macro which uses code to populate certain cells in a document and
then prints this page.
I would like to be able to use code to generate a sequential whole number
each time the macro is run and place this number in a cell on the document to
be printed. Thus whenever the document is printed it is numbered and this
number increases by one each time.

How can this be done please?

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
where can I see my question and answer? Yesterday I ask a question IP Excel Discussion (Misc queries) 2 May 10th 08 04:08 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good davegb Excel Programming 1 May 6th 05 06:35 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 27th 05 07:46 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 23 April 23rd 05 09:26 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 22nd 05 03:30 PM


All times are GMT +1. The time now is 03:41 AM.

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

About Us

"It's about Microsoft Excel"