Re: Fast way to generate unique strings

From: JE McGimpsey (jemcgimpsey_at_mvps.org)
Date: 10/26/04


Date: Tue, 26 Oct 2004 11:01:25 -0600

Don't know about the fastest, but this returns 100 strings of 100
characters in the blink of an eye...

    Public Function GetUniqueStrings( _
                ByRef Strings() As String, Length As Long)
        Dim i As Long
        Dim j As Long
        For i = LBound(Strings) To UBound(Strings)
            Strings(i) = Space(Length)
            For j = 1 To Length
                Mid(Strings(i), j, 1) = Chr(Int(97 + Rnd() * 26))
            Next j
        Next i
    End Function

Called as:

    Public Sub try()
        Dim s(1 To 100) As String
        GetUniqueStrings s, 100
        Range("A1").Resize(UBound(s)).Value = Application.Transpose(s)
    End Sub
    

In article <ul2IpS3uEHA.1448@TK2MSFTNGP10.phx.gbl>,
 R Avery <ravery74@yahoo.co.uk> wrote:

> what is the fastest VBA code to generate a list of random strings of a
> specified length.
>
> the function prototype i want is
>
> sub GetUniqueStrings(Strings() as string, Length as long)