+ Reply to Thread
Results 1 to 10 of 10

Formula using date and time to generate unique ID

Hybrid View

  1. #1
    Registered User
    Join Date
    03-26-2007
    Posts
    92

    Formula using date and time to generate unique ID

    Hello -

    I am looking for a way to generate a unique ID in A1 using the date and time B1 had data input in a YYMMDDhhmmss format. I can't use the NOW() formula as that updates every time Excel is opened. Once the number is generated, I need it to stay the same. Does anyone have any suggestions on how to do this?

    Thanks!

  2. #2
    Forum Expert
    Join Date
    12-11-2011
    Location
    Netherlands
    MS-Off Ver
    office 365
    Posts
    3,725

    Re: Formula using date and time to generate unique ID

    You need VBA
    If you dont want that use :
    <ctrl;> <space> <ctrl shift :>
    Willem
    English is not my native language sorry for errors
    Please correct me if I'm completely wrong

  3. #3
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Formula using date and time to generate unique ID

    You'll need a VBA Change Event Code for that...

    something like this
    Right click on the Sheet's Tab - View code
    Paste the following

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim myrange As Range, c As Range
    Set myrange = Intersect(Target, Range("B:B"))
    If Not myrange Is Nothing Then
        For Each c In myrange
            With Cells(c.Row, "A")
                .Value = Format(Now, "YYMMDDhhmmss")
                .NumberFormat = "0"
            End With
        Next c
    End If
    End Sub

  4. #4
    Registered User
    Join Date
    03-26-2007
    Posts
    92

    Re: Formula using date and time to generate unique ID

    Thank you for the suggestions! I tried the VBA code Johnmo1 shared. The number is changing every time B1 is changed. Is there a way to make this a static number?

  5. #5
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Formula using date and time to generate unique ID

    OK, so it needs to stay the same even if B1 is changed AGAIN later ?

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim myrange As Range, c As Range
    Set myrange = Intersect(Target, Range("B:B"))
    If Not myrange Is Nothing Then
        For Each c In myrange
            With Cells(c.Row, "A")
                If .Value = "" Then
                    .Value = Format(Now, "YYMMDDhhmmss")
                    .NumberFormat = "0"
                End If
            End With
        Next c
    End If
    End Sub

  6. #6
    Registered User
    Join Date
    03-26-2007
    Posts
    92

    Re: Formula using date and time to generate unique ID

    Quote Originally Posted by Jonmo1 View Post
    OK, so it needs to stay the same even if B1 is changed AGAIN later ?
    Yes. I'm essentially creating a log with the YYMMDDhhmmss as a ticket number.

  7. #7
    Registered User
    Join Date
    03-26-2007
    Posts
    92

    Re: Formula using date and time to generate unique ID

    Does anyone have any more suggestions on how to make it a static entry with VBA?

  8. #8
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Formula using date and time to generate unique ID

    Quote Originally Posted by penny View Post
    Does anyone have any more suggestions on how to make it a static entry with VBA?
    Did you try my last suggestion from post #5

  9. #9
    Registered User
    Join Date
    03-26-2007
    Posts
    92

    Re: Formula using date and time to generate unique ID

    Quote Originally Posted by Jonmo1 View Post
    Did you try my last suggestion from post #5
    My apologies! I think I mistyped the first time I tried it. It works great now, thank you!

  10. #10
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Formula using date and time to generate unique ID

    You're welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Generate a new/unique number each time template (2003) is used
    By rls231 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-08-2013, 01:30 PM
  2. Formula to generate unique random numbers?!?
    By aims in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-07-2013, 03:14 PM
  3. [SOLVED] Generate a unique time stamp per x instruction cycles? Is it possible?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-03-2012, 09:14 AM
  4. Replies: 5
    Last Post: 11-16-2011, 01:25 PM
  5. How can I generate a unique number each time a form is printed?
    By homaxlinda in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-17-2006, 04:55 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1