Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Sequential Numbering in a Template

Hi there

I have used the sequential numbering code on the McGimpsey site for a
template I have designed in Excel to insert the next consecutive number each
time the template is opened into a new workbook.

However now what happens is when I save the workbook and reopen it, it
automatically inserts the next sequential number.

How do I restrict the code to inserting a new number into a new workbook
when the template is used but not re-inserting a new number every time the
saved workbook is re-opened.

Thank you, Silena
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Sequential Numbering in a Template



Read JE McGimpseys code properly and you will see it uses IsEmpty and if
that evaluates as false nothing happens. Apologies to JE McGimpsey for
posting his code
without permission

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

Mike


"Silena K-K" wrote:

Hi there

I have used the sequential numbering code on the McGimpsey site for a
template I have designed in Excel to insert the next consecutive number each
time the template is opened into a new workbook.

However now what happens is when I save the workbook and reopen it, it
automatically inserts the next sequential number.

How do I restrict the code to inserting a new number into a new workbook
when the template is used but not re-inserting a new number every time the
saved workbook is re-opened.

Thank you, Silena

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Sequential Numbering in a Template

Dave Peterson posted this a while back.

If the workbook has never been saved, which is the case with a newly created
workbook from the Template, the invoice number will increment.

After saving, the number will not increment when opening that saved workbook.

Private Sub Workbook_Open()
if thisworkbook.path = "" then
'it's never been saved, so increment
Sheet1.Range("H16").Value = Sheet1.Range("H16").Value + 1
end if
End Sub


Gord Dibben MS Excel MVP

On Tue, 1 Apr 2008 11:35:00 -0700, Silena K-K
wrote:

Hi there

I have used the sequential numbering code on the McGimpsey site for a
template I have designed in Excel to insert the next consecutive number each
time the template is opened into a new workbook.

However now what happens is when I save the workbook and reopen it, it
automatically inserts the next sequential number.

How do I restrict the code to inserting a new number into a new workbook
when the template is used but not re-inserting a new number every time the
saved workbook is re-opened.

Thank you, Silena


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
Sequential numbering Scott Hemphill Excel Discussion (Misc queries) 2 July 24th 07 05:24 PM
PO with sequential numbering with start / end numbering [email protected] Excel Discussion (Misc queries) 1 April 24th 07 03:38 PM
Sequential Numbering Mel Excel Discussion (Misc queries) 10 May 9th 06 03:12 PM
Sequential numbering REELAXER Excel Worksheet Functions 1 June 30th 05 12:25 AM
Sequential Numbering. Rodney New Users to Excel 3 May 2nd 05 09:34 PM


All times are GMT +1. The time now is 08:44 PM.

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"