Increment Purchase Order Number

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

Guest

Hi,
I've just looked through several functions to look for a way to increment a
number each time a template is opened. It's proving to consume more time
than anticipated.

Can anyone help?
Thanks!
 
Hi Paul,
Thanks for your response. I was able to quickly find the code for what I
want from the site you recommended. The problem is, it's not producing the
expected result. Here's the code which, when put in a template's
ThisWorkbook code module, should produce an incremented sequential number
each time the template is used to generate a document:

Private Sub Workbook_Open()
Const sAPPLICATION As String = "Excel"
Const sSECTION As String = "Invoice"
Const sKEY As String = "Invoice_key"
Const nDEFAULT As Long = 1&
Dim nNumber As Long

With ThisWorkbook.Sheets("Invoice")
With .Range("B1")
If IsEmpty(.Value) Then
.Value = Date
.NumberFormat = "dd mmm yyyy"
End If
End With
With .Range("B2")
If IsEmpty(.Value) Then
nNumber = GetSetting(sAPPLICATION, sSECTION, sKEY,
nDEFAULT)
.NumberFormat = "@"
.Value = Format(nNumber, "0000")
SaveSetting sAPPLICATION, sSECTION, sKEY, nNumber + 1&
End If
End With
End With
End Sub

My result: When I choose to "enable macros", nothing happens. I've
duplicated the sample worksheet to ensure that the cell references in this
macro reflect properly in my worksheet. I've also named the template
"Invoice" and renamed sheet1 "Invoice".

Hopefully, this is possible for a VB newbie.
Thanks again, Lorrie
 

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