Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Long autonumber beginning with a 0 (zero)

I've found this very nice script for autonumber on a website. Everything
works just fine, but I need som help, please.
The autonumber starts at 41160 and increase with one everytime I open
it. But I want to add a "0" (zero) in the beginning of the autonumber,
instead of 41160 I want the output to be 041160.

The script I use:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim x As Boolean, y As Long
y = Worksheets("Blad1").Range("T2").Value + 1
Set fs = CreateObject("Scripting.FileSystemObject")
x = fs.fileexists("C:\indexlog.txt")
If x Then Kill "C:\indexlog.txt"
Open "C:\indexlog.txt" For Output As #1
Print #1, y
Close #1
End Sub

Private Sub Workbook_Open()
Open "C:\indexlog.txt" For Input As #1
Input #1, x
Close #1
Worksheets("Blad1").Range("T2") = x
End Sub
-

--
//Jst
Reclaim Your Inbox!
http://www.mozilla.org/products/thunderbird/
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Long autonumber beginning with a 0 (zero)

Assume you want a 6 digit string and if the value of the number would be 6
digits, you would not want a leading zero.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim x As Boolean, y As Long
y = Worksheets("Blad1").Range("T2").Value + 1
Set fs = CreateObject("Scripting.FileSystemObject")
x = fs.fileexists("C:\indexlog.txt")
If x Then Kill "C:\indexlog.txt"
Open "C:\indexlog.txt" For Output As #1
Print #1, y
Close #1
End Sub

Private Sub Workbook_Open()
Dim x as long
Open "C:\indexlog.txt" For Input As #1
Input #1, x
Close #1
Worksheets("Blad1").Range("T2") = "'" & format( x,"000000")
End Sub

--
Regards,
Tom Ogilvy

"jst_se" wrote in message
...
I've found this very nice script for autonumber on a website. Everything
works just fine, but I need som help, please.
The autonumber starts at 41160 and increase with one everytime I open
it. But I want to add a "0" (zero) in the beginning of the autonumber,
instead of 41160 I want the output to be 041160.

The script I use:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim x As Boolean, y As Long
y = Worksheets("Blad1").Range("T2").Value + 1
Set fs = CreateObject("Scripting.FileSystemObject")
x = fs.fileexists("C:\indexlog.txt")
If x Then Kill "C:\indexlog.txt"
Open "C:\indexlog.txt" For Output As #1
Print #1, y
Close #1
End Sub

Private Sub Workbook_Open()
Open "C:\indexlog.txt" For Input As #1
Input #1, x
Close #1
Worksheets("Blad1").Range("T2") = x
End Sub
-

--
//Jst
Reclaim Your Inbox!
http://www.mozilla.org/products/thunderbird/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Long autonumber beginning with a 0 (zero)

Thank you, Tom!
I tried Worksheets("Blad1").Range("T2") = "0" & x
But your solution was much better and works perfect.

Regards,
Jst

Tom Ogilvy wrote:
Assume you want a 6 digit string and if the value of the number would be 6
digits, you would not want a leading zero.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim x As Boolean, y As Long
y = Worksheets("Blad1").Range("T2").Value + 1
Set fs = CreateObject("Scripting.FileSystemObject")
x = fs.fileexists("C:\indexlog.txt")
If x Then Kill "C:\indexlog.txt"
Open "C:\indexlog.txt" For Output As #1
Print #1, y
Close #1
End Sub

Private Sub Workbook_Open()
Dim x as long
Open "C:\indexlog.txt" For Input As #1
Input #1, x
Close #1
Worksheets("Blad1").Range("T2") = "'" & format( x,"000000")
End Sub



--
Reclaim Your Inbox!
http://www.mozilla.org/products/thunderbird/
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
http://CannotDeleteFile.net - Cannot Delete File? Try Long Path ToolFilename is too long? Computer Complaining Your Filename Is Too Long? TheLong Path Tool Can Help While most people can go about their businessblissfully unaware of the Windo Max Loger Excel Discussion (Misc queries) 0 June 14th 11 04:30 PM
Long Long Long Nested If Function sed Excel Discussion (Misc queries) 4 December 9th 09 06:44 PM
Is it possible to set up an AutoNumber in Excel? Chris Excel Worksheet Functions 1 September 19th 07 02:22 AM
autonumber Hardy Excel Discussion (Misc queries) 4 November 24th 05 05:40 PM
How can I autonumber in excel? Tracy Excel Discussion (Misc queries) 2 August 22nd 05 08:50 PM


All times are GMT +1. The time now is 10:41 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"