Results 1 to 5 of 5
  1. #1
    Delta223 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    38

    Random value generation?

    Hi all,



    Anyone know if it is possible to generate random values using a formula in Excel?

    My ideal values would be: Alpha Alpha Numeral Numeral Numeral (ex KF938, MC823, etc) This gives me all the easy to remember SKU #s I want.

    If random alphas aren't possible I can also use 4 or 5 digit numeral values (ie 8329, 27463)

    Thanks!
    Last edited by Delta223; 01-12-2012 at 11:07 AM.

  2. #2
    apr pillai's Avatar
    apr pillai is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2010
    Location
    Alappuzha, India
    Posts
    209
    1. Press ALT+F11 to display the VBA Window.
    2. Insert a Standard Module.
    3. Copy and paste the following Code into the module and save it.
    4. Code:
      Public Function CustRnd() As String
      Dim strAlpha As String, num As Integer
      Dim strout As String, j As Integer
      
      Randomize (Timer)
      
      strout = ""
      For j = 1 To 2
        num = Int(Rnd(1) * 26) + 1
        strout = strout & Chr$(64 + num)
      Next
      
      j = Int(Rnd(1) * 999) + 1
      strout = strout & Format(j, "000")
      CustRnd = strout
      
      End Function
    5. Press ALT+F11 again to go back to the worksheet.
    6. Enter the Expression =CustRnd() in any cell where you want a Random Number in XXnnn format, where XX represents alphabets and rest numerals.

    OR


    Highlight a rectangular Range, Type =CustRnd(), press and hold the Ctrl Key then press Enter Key.


    You may use the CustRnd() function combined with other expressions also.

  3. #3
    Delta223 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    38
    Thanks so much! I'll try it now

  4. #4
    Delta223 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    38
    Hi,

    I decided to go with one less numeral to make it less confusing (HF32, UC04, XL87, etc)

    I tried to change the VBA code but could not get it to work. How can I reduce the code to create Alpha Alpha Numeral Numeral?

    Thanks again!

  5. #5
    apr pillai's Avatar
    apr pillai is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2010
    Location
    Alappuzha, India
    Posts
    209
    Change the following lines in the code

    Code:
    j = Int(Rnd(1) * 999) + 1
    strout = strout & Format(j, "000")
    To

    Code:
    j = Int(Rnd(1) * 99) + 1
    strout = strout & Format(j, "00")
    i.e. 999 to 99 and Format(j,"000") to Format(j,"00")
    Last edited by apr pillai; 01-12-2012 at 12:32 PM. Reason: Edited to include the format line change too

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Automatic Next number generation
    By MicroMan in forum Programming
    Replies: 17
    Last Post: 10-21-2011, 05:57 PM
  2. Report Generation from with a Form
    By amangupts in forum Reports
    Replies: 29
    Last Post: 07-22-2011, 08:40 AM
  3. Report Generation
    By Lorlai in forum Reports
    Replies: 5
    Last Post: 07-01-2011, 11:13 AM
  4. Automate Number Generation
    By Kero in forum Access
    Replies: 5
    Last Post: 04-28-2011, 01:49 PM
  5. Password generation does not seem random
    By ducecoop in forum Access
    Replies: 6
    Last Post: 11-15-2010, 02:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums