+ Reply to Thread
Results 1 to 2 of 2

random word generator

  1. #1
    Registered User
    Join Date
    04-17-2007
    Posts
    6

    Question random word generator

    Hi,

    I am now completely stuck.

    I have the following VBA script to generate a string of random characters in a specific cell.
    I would like this to work for a number of cell at the same time.

    Is this possible? how can i change my existing code so that instead of D15 a range of selected cells (for example C10 thru to C15 and E5) can be generated at the same time however making all the codes different (and if possible unique)

    would really be appreciated.


    Sub PasswordGenerator()
    Dim Password As String
    Dim PasswordLength As Byte
    Dim LC As Byte 'Loop Counter
    Dim strRndmChr As String
    Dim LAC As Byte 'Lowest Ascii Character
    Dim HAC As Byte 'Highest Ascii Character
    Dim UseSymbolics As Boolean
    Dim HasSymbolics As Boolean
    Dim RandomNumber As Byte

    'Set parameters.
    PasswordLength = 6
    'Visit www.lookuptables.com for the ascii table.
    LAC = Asc("0")
    HAC = Asc("z")
    UseSymbolics = False

    Randomize
    For LC = 1 To PasswordLength
    'To produce random integers in a given range, use this formula:
    'Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
    Do
    RandomNumber = Int((HAC - LAC + 1) * Rnd + LAC)
    strRndmChr = Chr(RandomNumber)
    HasSymbolics = CheckSymbolics(RandomNumber)
    Loop Until UseSymbolics = True Or HasSymbolics = False
    Password = Password & strRndmChr
    Next LC
    Range("D15").Value = Password
    'ActiveCell = Password

    End Sub
    Private Function CheckSymbolics(RandomNumber As Byte)
    If (RandomNumber >= 33 And RandomNumber <= 47) Or _
    (RandomNumber >= 58 And RandomNumber <= 64) Or _
    (RandomNumber >= 91 And RandomNumber <= 96) Or _
    (RandomNumber >= 123 And RandomNumber <= 126) Then _
    CheckSymbolics = True Else: CheckSymbolics = False
    End Function

  2. #2
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: random word generator

    You could actually use native excel function to generate password chars.

    See attached..

    by the Way Your Post doesn't comply with the rule #3 of Forum Rules
    Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Select your code and click the [#] button at the top of the post window (if you are editing an existing post, press Go Advanced to see the [#] button). The result will appear like this in the post window:

    Please Login or Register  to view this content.
    ... and appear like this when posted:

    Code:
    your code here ...
    and here ...
    and here
    You can also type the code tags in manually if you prefer. For more information about these and other tags, click here.
    Attached Files Attached Files
    Люди, питающие благие намерения, как раз и становятся чудовищами.

    Regards, ?Born in USSR?
    Vusal M Dadashev

    Baku, Azerbaijan

+ 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