Auto numbering a cell

go4broke

New Member
Joined
Jan 6, 2003
Messages
24
I am looking for a way to have a specific cell sequentially numbered using a beginning parameter. I thought about using a date as a number value, but it starts to high. Possibly an entry in Windows registry or a flat file located on the local system.

Any suggestions???

Thanks
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
This will increment the number in cell A1 each time the workbok is opened:

Code:
Private Sub Workbook_Open()
    Dim FName As String
    Dim FNo As String
    Dim x As Long
    FName = Application.Path & Application.PathSeparator & "Number.Txt"
    FNo = FreeFile
    x = 0
    On Error Resume Next
    Open FName For Input As #FNo
    Input #FNo, x
    x = x + 1
'   *** Change range reference to suit ***
    Range("A1").Value = x
    Close #FNo
    FNo = FreeFile
    Open FName For Output As #FNo
    Write #1, x
    Close #FNo
End Sub

Is that what you want?
 
Upvote 0
The suggestion is if the same file is opened. I am looking for a solution that works with a template where the file will be unique each time, filled in, and saved/submitted for use as if it were a pre-numbered paper form.

Thanks
 
Upvote 0
Save the workbook as a template. Then choose File, New and select the template. Excel will open an instance of the template as a new xls file. The number will be updated.
 
Upvote 0
This works GREAT!! One additional nuance.

I have an OS SET operator with a user name value. How can I access this to get the first 3 characters and concatenate this with the sequencer.

Thanks for the help!!!
 
Upvote 0
I was trying to describe an "operating system" set value from the autoexec.bat file.

The value is something like:
set user=SAMPLE

Thanks
 
Upvote 0
You can use the Environ function:

UName = Left(Environ("user"),3)

then

Range("A1").Value = UName & x

If you always wanted the number to be say 5 characters then use:

Range("A1").Value = UName & Format(x,"00000")
 
Upvote 0
Task completed. Your help is much appreciated!!

I also added my own uCase() function so the naming would be the same, as well as & " - " to the value.

Thanks again!!!!
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,592
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top