+ Reply to Thread
Results 1 to 15 of 15

Unique ID

  1. #1
    Registered User
    Join Date
    08-13-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    9

    Unique ID

    Hi all,

    What I would like to do:

    Each time I open a excel file I want a cell A to have a unique ID based on Time and Seconds ie 10:23:33. (Time and Seconds it was opened)

    What I would then like to do is convert this into the following format
    102333

    Which removes the ":"

    Please help.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Unique ID

    Try
    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    08-13-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Unique ID

    ok, I have added this to the Visual Basic Editor and when I open the file the cell is empty no values inside it. Do I need to call this code in my cell?

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Unique ID

    Use:

    Please Login or Register  to view this content.

    For International purposes I use Sheets (1), instead of Sheet1.
    I added a hyphen, otherwise the formatting "HH" doesn't make sense.
    Cfr the attachment.
    Attached Files Attached Files



  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Unique ID

    Workbook Event code should be added to the workbook code module:

    Copy the Excel VBA code that you want to use
    Select the workbook in which you want to store the code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    In the Project Explorer, find your workbook, and open the list of Microsoft Excel Objects
    Right-click on the ThisWorkbook object, and choose View Code
    Where the cursor is flashing, choose Edit | Paste

  6. #6
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Unique ID

    Roy,

    if I understand correctly the OP wants it to work when opening any workbook ??

    Each time I open a excel file I want a cell

  7. #7
    Registered User
    Join Date
    08-13-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Unique ID

    Correct, whenever a user opens that specific workbook I want the cell to show the latest date and time as in the format specfied above.
    Can you show me how to do this please?

  8. #8
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Unique ID

    Then follow steps described under post #4 and 5

  9. #9
    Registered User
    Join Date
    08-13-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Unique ID

    I get an erro message the object doesnt support this property or method
    runtime error 438.
    if i type Sheet1.Cells(1, 1) = Format(Time, "'HHMMSS")
    where sheet1 is the name of my sheet
    i get the following
    runtime error 424
    object required

  10. #10
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Unique ID

    Try
    Please Login or Register  to view this content.

  11. #11
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Unique ID

    Please reread my post:

    sheets(1). not sheet1.

    But why not using an Excel Formula ?

    PHP Code: 
    =TEXT(NOW();"HHMMSS"
    Last edited by snb; 10-31-2011 at 10:08 AM.

  12. #12
    Registered User
    Join Date
    08-13-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Unique ID

    when I use the code it returns

    142638

    in the cell, this doesnt look like date and time to me???


    I tried using =TEXT(NOW();"HHMMSS")
    but it returns the formula contains and error...

  13. #13
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Unique ID

    when I use the code it returns

    142638

    in the cell, this doesnt look like date and time to me???
    You asked for the time in your first post ?

    If you need date also then try
    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    works replacing ; with , ( regional settings)

  14. #14
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Unique ID

    Please reread this thread....


    PHP Code: 
    =TEXT(NOW();"YYYYMMDDHHMMSS"
    or
    Please Login or Register  to view this content.

  15. #15
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Unique ID

    snb

    I think the OP needs to replace the semi colon with a comm in your TEXT function

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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