How do you add 1 to an invoice number in Excel. Formula for th
I tried this and get and "invalid outside procedure" with the "UniqueID"
hi-lited. what am I doing wrong. Susan
"Bob Phillips" wrote:
You could define a name in your workbook, and use this value when the file
opens.
Add this code to theThisWorkbook code module within the workbook and it will
automatically increment the Name UniqueId every time the workbook is opened.
You can then acess that name in your code by plugging this into the existing
code that needs the Id.
Evaluate(ThisWorkbook).Names("__UniqueId").RefersT o)
'-------------------------------------------------------------
Private Sub Workbook_Open()
'-------------------------------------------------------------
GetId
End Sub
'-------------------------------------------------------------
Private Sub GetId()
'-------------------------------------------------------------
Dim myId As Long
myId = 1 ' in case it doesn't already exist
On Error Resume Next
myId = Evaluate(ThisWorkbook.Names("__UniqueId").RefersTo ) + 1
ThisWorkbook.Names.Add Name:="__UniqueId", RefersTo:="=" & myId
End Sub
'-------------------------------------------------------------
'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code
--
HTH
Bob Phillips
"Susan" wrote in message
...
I'm trying to set up my own invoices. What I can't seem to do is create a
cell for my invoice number, that every time I open the file it adds 1
(0ne)
to the invoice number. Does anyone have a macro - formula for doing this?
Thank you
|