+ Reply to Thread
Results 1 to 7 of 7

Creating a unique form number upon Workbook Open

  1. #1
    Registered User
    Join Date
    09-18-2006
    Posts
    30

    Question Creating a unique form number upon Workbook Open

    Hello,

    I'm attempting to construct a form that will be used a few times each day. Each time the form is opened I want it to include a unique number in cell R3. This number should be MMDDYY-XX where XX is a random two digit number.

    I'm a basic VBA user and have come up with the following:

    Please Login or Register  to view this content.
    This seems to work, except that each time I open the file it has the same two digit random number. Can somebody please explain to me why it isn't generating a new random number each time?

    Thanks in advance
    Lance

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Creating a unique form number upon Workbook Open

    Hi, Lance,

    maybe use Randomize:
    Please Login or Register  to view this content.
    IŽd go with a counter instead of a random number which should be formatted as 2 digits if wanted.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    09-18-2006
    Posts
    30

    Re: Creating a unique form number upon Workbook Open

    Holger,
    The randomize worked, thanks.

    I like the idea of a counter, but unsure how to go about it. What would that look like so that the counter would reset daily?

    Thanks

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Creating a unique form number upon Workbook Open

    Hi, lancekeith,

    maybe like this:
    Please Login or Register  to view this content.
    To make sure that it works in each every new year as well I would change the datestamp from mmddyy to yymmdd.

    Ciao,
    Holger
    Last edited by HaHoBe; 03-15-2013 at 01:18 PM.

  5. #5
    Registered User
    Join Date
    09-18-2006
    Posts
    30

    Re: Creating a unique form number upon Workbook Open

    Holger,

    I tried your code, like this

    Please Login or Register  to view this content.
    I believe I understand what it is supposed to do, and it makes sense, but it doesn't seem to work.
    Lance

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Creating a unique form number upon Workbook Open

    Hi, Lance,

    ... but it doesn't seem to work.
    Do you get a run-time error or is the string not put into the proper range (the code refers to the active sheet as no worksheet name is listed)? Maybe have a look at the attached sample workbook.

    Ciao,
    Holger
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    09-18-2006
    Posts
    30

    Re: Creating a unique form number upon Workbook Open

    Thank you
    The problem was that R3 was a merged cell and I had the wrong cell referenced.

    Appreciate the help

+ 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