Home |
Search |
Today's Posts |
#7
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hello Michele,
Try this UDF: Function ranpw(l As Long, ByVal ca As Long, ByVal cn As Long) As String 'random alpha-numeric password with length l and a minimum of 'ca alpha characters and cn numerical characters Dim s As String, sr As String Dim r As Long, i As Long Application.Volatile s = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklm nopqrstuvwxyz" If l < 1 Or ca < 0 Or cn < 0 Or l < ca + cn Then ranpw = CVErr(xlErrNum) Exit Function End If For i = 1 To l If l - i + 1 = ca Then r = 52 * Rnd() + 11 ElseIf l - i + 1 = cn Then r = 10 * Rnd() + 1 Else r = 62 * Rnd() + 1 End If If r 10 Then If ca 0 Then ca = ca - 1 Else If cn 0 Then cn = cn - 1 End If sr = sr & Mid(s, r, 1) Next i ranpw = sr End Function Press ALT + F11, insert a module, and copy this function into the module. If you need a password of length 5 with at least 2 alpha and 2 numerical characters: =ranpw(5,2,2) HTH, Bernd |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Random cell/number and dont repeat selected cell/number | Excel Discussion (Misc queries) | |||
Pulling Data off Web - Need Function Help | Excel Worksheet Functions | |||
How do I generate only one random number without it refreshing? | Excel Worksheet Functions | |||
same number appears in a random number generator | Excel Worksheet Functions | |||
Random Number Questions | Excel Worksheet Functions |