Number in forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!!
I shall make this form, and in this form
i shall use a number like a ID there every
time i start this form i get a new number
like if the last number i use was 0098 then
i get 0099 when i start the form. And when
i save the file the file name shal bee the number
i just get like 0099. hope someone can help how to do this

Best regards

Alvin
 
Hi alvin

You can format the cell like this
Ctrl-1
Number>custom
Type : Enter 0000 there

In a macro you can use this

With Sheets("sheet1").Range("A1")
..Value = .Value + 1
End With
 
Hi ALvin,

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").RefersTo)


'-------------------------------------------------------------
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
UniqueId = Evaluate(ThisWorkbokNames("_UniqueId").RefersTo) + 1
ThisWorkbook.Names.Add Name:="_UniqueId", RefersTo:="=" & myId

End Sub
'-------------------------------------------------------------


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Hi Ron,

I was reading what you wrote to Alvin, and I tried your suggestion.
However, I can't make it work for me. Does it make a difference in the
version of excel you are using?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top