Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Question on autonumber


I’m sure this have been asked a thousand times, but I just need
starting hand. I have built a quote sheet and now I want to have th
quote number automatically update with the next available number. I a
thinking I can put a TXT file in the same dir and then call it fro
excel but I don’t know where to write. I want to call it Onopen.

I am thinking it should look like this. ( I’m a novice with code.)

Breneck Quote Sheet 2.Main.Range (“C17”).Value = NextSeqNumbe
(“Quote.txt”)

Am I on the right track

--
Xeno
-----------------------------------------------------------------------
Xenos's Profile: http://www.excelforum.com/member.php...fo&userid=2652
View this thread: http://www.excelforum.com/showthread.php?threadid=47197

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Question on autonumber

There's a number of ways - it would probably depend on how you operate
and the number of users using the workbook. You could store it in the
workbook properties or even in the cell itself and just increment it.

However, I guess you have multiple users and therefore people might be
opening it as read only therefore you want to store it elsewhere. In
that case, to write/read from a file so something like the below.

Note that this obviously doesn't prevent quote numbers from not being
used when someone just opens and closes a workbook for no reason.

HTH,
Gareth

In your ThisWorkbook code module place:

'assuming your worksheet is named 'Breneck Quote'
Private Sub Workbook_Open
Thisworkbook.sheets("Breneck Quote").Range ("C17").Value _
= fcnGetNextAvailableQuoteNumber
End Sub

Private Function fcnGetNextAvailableQuoteNumber() as string
Const myFileName as string = "quotenumber.txt"
Dim F as long
Dim MyNo as Variant

'get the quote number
If Dir(ThisWorkbook.Path & "\" & myFileName) < "" Then
F = FreeFile
Open Thisworkbook.path & "\" & myFileName _
for input as #F
Input #F, MyNo
Close #F
End if

'Set to 1 if it was empty (or something else was in the file)
If not isnumeric(myno) then MyNo = 1 else MyNo = MyNo +1

'return the number (I assume you want it formatted with
'zeros or something
fcnGetNextAvailableQuoteNumber = Format(MyNo,"00000000")

'update the file
F = FreeFile
Open Thisworkbook.path & "\" & myFileName _
for output as #F
Print #F, MyNo
Close #F

End function


Xenos wrote:
I’m sure this have been asked a thousand times, but I just need a
starting hand. I have built a quote sheet and now I want to have the
quote number automatically update with the next available number. I am
thinking I can put a TXT file in the same dir and then call it from
excel but I don’t know where to write. I want to call it Onopen.

I am thinking it should look like this. ( I’m a novice with code.)

Breneck Quote Sheet 2.Main.Range (“C17”).Value = NextSeqNumber
(“Quote.txt”)

Am I on the right track?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Question on autonumber


Gareth, Thank you… it rocks.


--
Xenos
------------------------------------------------------------------------
Xenos's Profile: http://www.excelforum.com/member.php...o&userid=26526
View this thread: http://www.excelforum.com/showthread...hreadid=471973

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Question on autonumber

You're welcome mate.

Xenos wrote:
Gareth, Thank you… it rocks.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Question on autonumber


Gearth, how do I direct the txt file to c:\Quote ?


--
Xenos
------------------------------------------------------------------------
Xenos's Profile: http://www.excelforum.com/member.php...o&userid=26526
View this thread: http://www.excelforum.com/showthread...hreadid=471973



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Question on autonumber

Hi,

Replace the function fcnGetNextAvailableQuoteNumber I gave you with the
below one.

FYI - I just changed
Const myFileName as string = "quotenumber.txt"
to
Const myFileName as string = "c:\quote\quotenumber.txt"

and instead of using ThisWorkbook.Path & "\" & myFileName I use just
myFilename.

G

Private Function fcnGetNextAvailableQuoteNumber() as string
Const myFileName as string = "c:\quote\quotenumber.txt"
Dim F as long
Dim MyNo as Variant

'get the quote number
If Dir(myFileName) < "" Then
F = FreeFile
Open myFileName for input as #F
Input #F, MyNo
Close #F
End if

'Set to 1 if it was empty (or something else was in the file)
If not isnumeric(myno) then MyNo = 1 else MyNo = MyNo +1

'return the number (I assume you want it formatted with
'zeros or something
fcnGetNextAvailableQuoteNumber = Format(MyNo,"00000000")

'update the file
F = FreeFile
Open myFileName for output as #F
Print #F, MyNo
Close #F

End function

Xenos wrote:
Gearth, how do I direct the txt file to c:\Quote ?


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
lookup and autonumber rajeshparikh64 Excel Worksheet Functions 2 March 26th 06 11:19 AM
Autonumber in a cell Omar Menjivar Excel Discussion (Misc queries) 0 March 11th 06 12:26 AM
Autonumber from Form ES New Users to Excel 2 February 7th 06 04:58 PM
autonumber Hardy Excel Discussion (Misc queries) 4 November 24th 05 05:40 PM
autonumber values rlmanderson Excel Worksheet Functions 1 March 10th 05 11:43 PM


All times are GMT +1. The time now is 06:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"