Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Pat Pat is offline
external usenet poster
 
Posts: 122
Default Auto unique numbering


I want a unique number automatically inserted using the Worksheet_Change
event. When a cell in column D contains a value column E will automatically
display a unique 13 digit number which is incremented by one. The worksheet
will be sorted regularly, so taking away the worry of knowing what the last
number used to avoid duplicates is vital.

Anyone got the know-how on this?
Many thanks!
Pat



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Auto unique numbering

Hi
try
Private Sub Worksheet_Change(ByVal Target As Range)
Dim counter
If Target.Cells.Count 1 Then Exit Sub
If Target.Column < 4 Then Exit Sub
On Error GoTo errhandler
Application.EnableEvents = False
With Target
If .Value = "" Then
.Offset(0, 1).ClearContents
Else
counter = Application.WorksheetFunction.Max(Me.Range("E:E")) + 1
.Offset(0, 1).NumberFormat = "0000000000000"
.Offset(0, 1).Value = counter
End If
End With

errhandler:
Application.EnableEvents = True
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany


Pat wrote:
I want a unique number automatically inserted using the
Worksheet_Change event. When a cell in column D contains a value
column E will automatically display a unique 13 digit number which is
incremented by one. The worksheet will be sorted regularly, so taking
away the worry of knowing what the last number used to avoid
duplicates is vital.

Anyone got the know-how on this?
Many thanks!
Pat


  #3   Report Post  
Posted to microsoft.public.excel.programming
Pat Pat is offline
external usenet poster
 
Posts: 122
Default Auto unique numbering

Hi Frank,
Your code worked beautifully. The only thing I need cleared up is if the
Offset is change as follows:

.Offset(0, 5).ClearContents
Else
counter = Application.WorksheetFunction.Max(Me.Range("E:E")) + 1
.Offset(0, 5).NumberFormat = "0000000000000"
.Offset(0, 5).Value = counter


incrementing does not take place, why would that be?

Regards and many thanks.
Pat

"Frank Kabel" wrote in message
...
Hi
try
Private Sub Worksheet_Change(ByVal Target As Range)
Dim counter
If Target.Cells.Count 1 Then Exit Sub
If Target.Column < 4 Then Exit Sub
On Error GoTo errhandler
Application.EnableEvents = False
With Target
If .Value = "" Then
.Offset(0, 1).ClearContents
Else
counter = Application.WorksheetFunction.Max(Me.Range("E:E")) + 1
.Offset(0, 1).NumberFormat = "0000000000000"
.Offset(0, 1).Value = counter
End If
End With

errhandler:
Application.EnableEvents = True
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany


Pat wrote:
I want a unique number automatically inserted using the
Worksheet_Change event. When a cell in column D contains a value
column E will automatically display a unique 13 digit number which is
incremented by one. The worksheet will be sorted regularly, so taking
away the worry of knowing what the last number used to avoid
duplicates is vital.

Anyone got the know-how on this?
Many thanks!
Pat




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Auto unique numbering

Hi
you're inserting the values in column I?. If yes change the line
counter = Application.WorksheetFunction.Max(Me.Range("E:E")) + 1

to
counter = Application.WorksheetFunction.Max(Me.Range("I:I")) + 1


--
Regards
Frank Kabel
Frankfurt, Germany


Pat wrote:
Hi Frank,
Your code worked beautifully. The only thing I need cleared up is if
the Offset is change as follows:

.Offset(0, 5).ClearContents
Else
counter = Application.WorksheetFunction.Max(Me.Range("E:E")) + 1
.Offset(0, 5).NumberFormat = "0000000000000"
.Offset(0, 5).Value = counter


incrementing does not take place, why would that be?

Regards and many thanks.
Pat

"Frank Kabel" wrote in message
...
Hi
try
Private Sub Worksheet_Change(ByVal Target As Range)
Dim counter
If Target.Cells.Count 1 Then Exit Sub
If Target.Column < 4 Then Exit Sub
On Error GoTo errhandler
Application.EnableEvents = False
With Target
If .Value = "" Then
.Offset(0, 1).ClearContents
Else
counter = Application.WorksheetFunction.Max(Me.Range("E:E")) + 1
.Offset(0, 1).NumberFormat = "0000000000000"
.Offset(0, 1).Value = counter
End If
End With

errhandler:
Application.EnableEvents = True
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany


Pat wrote:
I want a unique number automatically inserted using the
Worksheet_Change event. When a cell in column D contains a value
column E will automatically display a unique 13 digit number which
is incremented by one. The worksheet will be sorted regularly, so
taking away the worry of knowing what the last number used to avoid
duplicates is vital.

Anyone got the know-how on this?
Many thanks!
Pat


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
Create unique numbering system from three bits of data skimark Excel Discussion (Misc queries) 4 June 23rd 09 01:13 PM
aUTO nUMBERING Udayan New Users to Excel 2 March 12th 09 10:07 AM
Auto Numbering Andy JL New Users to Excel 3 November 23rd 05 05:09 AM
Auto Numbering jharkins Excel Discussion (Misc queries) 2 July 28th 05 11:46 PM
Auto Numbering Nicola Brennan[_2_] Excel Programming 1 November 9th 03 04:40 PM


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