View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
AA2e72E AA2e72E is offline
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?