Results 1 to 2 of 2

Excel 2007 & 2010 Static Random Unique Alphanumeric string across multiple sheets

Threaded View

  1. #1
    Registered User
    Join Date
    01-21-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    1

    Excel 2007 & 2010 Static Random Unique Alphanumeric string across multiple sheets

    Hi,

    I am new to VBA and wanted to make an excel file. I need to create an excel file with 15 sheets and each sheet will have 6 columns;

    1. Member ID (Mandatory)
    2. First Name (Mandatory)
    3. Last Name (Mandatory)
    4. Gender (Mandatory)
    5. Date of Birth (MM/DD/YY) format (Mandatory)
    6. Member Code

    All fields will be blank initially. Once a user enters/selects a value in the Member ID, First Name, Last Name, Gender & Date of Birth column, a Unique, Random, 15 character alphanumeric string (only upper case alphabets, no lower case alphabets) should be generated in the Member Code column.

    The value should not change even when data for next row is entered. After saving the excel workbook and re-opening it, it should retain all the unique random 15 character strings generated.

    I found a good function that can create a 15 character string as required, but I am unable to make it unique within the sheet & across the sheets in a workbook.

    The function is taken from this site
    http://www.ozgrid.com/forum/showthread.php?t=19314

    I modified the function slightly to suit my needs and changed it to this

    Function Pwd(iLength As Integer) As String
        Dim i As Integer, iTemp As Integer, bOK As Boolean, strTemp As String
        '48-57 = 0 To 9, 65-90 = A To Z, 97-122 = a To z
        'amend For other characters If required
        For i = 1 To iLength
            Do
                iTemp = Int((90 - 48 + 1) * Rnd + 48)
                Select Case iTemp
                Case 48 To 57, 65 To 90: bOK = True
                Case Else: bOK = False
                End Select
            Loop Until bOK = True
            bOK = False
            strTemp = strTemp & Chr(iTemp)
        Next i
        Pwd = strTemp
    End Function

    I can throw in some conditional statements to not run this script if the previous columns are empty, but I am unable to make it unique.

    Kindly help me out here.

    Thanks in anticipation !!!
    Vignan
    Last edited by svignan; 01-22-2013 at 06:31 AM.

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