Another way...
The code starts populating passwords from A2 (assuming A1 is header)<font face=Courier New><SPAN style="color:#00007F">Option</SPAN><SPAN style="color:#00007F">Explicit</SPAN><br><br><SPAN style="color:#00007F">Function</SPAN> GeneratePassword()<br> <SPAN style="color:#00007F">Dim</SPAN> PassLength<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Long</SPAN>, TempPass<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">String</SPAN>, i<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Long</SPAN><br> PassLength = Int((14 - 8 + 1) * Rnd + 8)<br> <SPAN style="color:#00007F">For</SPAN> i = 1<SPAN style="color:#00007F">To</SPAN> PassLength<br> TempPass = Chr(Int((126 - 33 + 1) * Rnd + 33))<br> GeneratePassword = GeneratePassword & TempPass<br> <SPAN style="color:#00007F">Next</SPAN> i<br><SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">Function</SPAN><br><br><SPAN style="color:#00007F">Sub</SPAN> RandomPasswordGenerator()<br> <SPAN style="color:#00007F">Dim</SPAN> Rng<SPAN style="color:#00007F">As</SPAN> Range<br> <SPAN style="color:#00007F">Dim</SPAN> Password<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">String</SPAN>, PrevPass<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">String</SPAN><br> <SPAN style="color:#00007F">Dim</SPAN> lCount<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Long</SPAN>, RptCount<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Long</SPAN>, X<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Long</SPAN>, PrevCount<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Long</SPAN><br> <SPAN style="color:#00007F">Dim</SPAN> oMat1<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Object</SPAN>, oMat2<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Object</SPAN><br> <SPAN style="color:#00007F">If</SPAN> Range("A2").Value = ""<SPAN style="color:#00007F">Then</SPAN><br>GenPass1:<br> RptCount = 0<br> Password = GeneratePassword<br> <SPAN style="color:#00007F">Set</SPAN> oMat1 =<SPAN style="color:#00007F">Nothing</SPAN><br> <SPAN style="color:#00007F">Set</SPAN> oMat2 =<SPAN style="color:#00007F">Nothing</SPAN><br> <SPAN style="color:#00007F">With</SPAN> CreateObject("VBScript.RegExp")<br> .Global =<SPAN style="color:#00007F">True</SPAN><br> .Pattern = "[A-Za-z]"<br> <SPAN style="color:#00007F">If</SPAN> .test(Password)<SPAN style="color:#00007F">Then</SPAN><br> <SPAN style="color:#00007F">Set</SPAN> oMat1 = .Execute(Password)<br> <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN><br> .Pattern = "[^A-Za-z]"<br> <SPAN style="color:#00007F">If</SPAN> .test(Password)<SPAN style="color:#00007F">Then</SPAN><br> <SPAN style="color:#00007F">Set</SPAN> oMat2 = .Execute(Password)<br> <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">For</SPAN> lCount = 1<SPAN style="color:#00007F">To</SPAN> Len(Password) - 2<br> <SPAN style="color:#00007F">If</SPAN> (Mid(Password, lCount, 1) = Mid(Password, lCount + 1, 1)) And _<br> (Mid(Password, lCount + 1, 1) = Mid(Password, lCount + 2, 1))<SPAN style="color:#00007F">Then</SPAN><br> RptCount = RptCount + 1<br> <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">Next</SPAN> lCount<br> <SPAN style="color:#00007F">If</SPAN> (oMat1.Count >= 3) And (oMat2.Count >= 2) And (RptCount = 0)<SPAN style="color:#00007F">Then</SPAN><br> Range("A2").Value = Password<br> <SPAN style="color:#00007F">Else</SPAN><br> <SPAN style="color:#00007F">GoTo</SPAN> GenPass1<br> <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">With</SPAN><br> <SPAN style="color:#00007F">Else</SPAN><br> lr = Range("A" & Rows.Count).End(xlUp).Row<br> <SPAN style="color:#00007F">If</SPAN> lr<= 21<SPAN style="color:#00007F">Then</SPAN><br> <SPAN style="color:#00007F">Set</SPAN> Rng = Range("A2", Range("A" & lr))<br> <SPAN style="color:#00007F">Else</SPAN><br> <SPAN style="color:#00007F">Set</SPAN> Rng = Range("A" & Rows.Count).End(xlUp).Offset(-19).Resize(20)<br> <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN><br> PrevPass = Range("A" & lr).Value<br>GenPass2:<br> RptCount = 0<br> PrevCount = 0<br> Password = GeneratePassword<br> <SPAN style="color:#00007F">Set</SPAN> oMat1 =<SPAN style="color:#00007F">Nothing</SPAN><br> <SPAN style="color:#00007F">Set</SPAN> oMat2 =<SPAN style="color:#00007F">Nothing</SPAN><br> <SPAN style="color:#00007F">On</SPAN><SPAN style="color:#00007F">Error</SPAN><SPAN style="color:#00007F">Resume</SPAN><SPAN style="color:#00007F">Next</SPAN><br> X = WorksheetFunction.Match(Password, Rng, 0)<br> <SPAN style="color:#00007F">If</SPAN> Err.Number = 0<SPAN style="color:#00007F">Then</SPAN><br> <SPAN style="color:#00007F">GoTo</SPAN> GenPass2<br> <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">With</SPAN> CreateObject("VBScript.RegExp")<br> .Global =<SPAN style="color:#00007F">True</SPAN><br> .Pattern = "[A-Za-z]"<br> <SPAN style="color:#00007F">If</SPAN> .test(Password)<SPAN style="color:#00007F">Then</SPAN><br> <SPAN style="color:#00007F">Set</SPAN> oMat1 = .Execute(Password)<br> <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN><br> .Pattern = "[^A-Za-z]"<br> <SPAN style="color:#00007F">If</SPAN> .test(Password)<SPAN style="color:#00007F">Then</SPAN><br> <SPAN style="color:#00007F">Set</SPAN> oMat2 = .Execute(Password)<br> <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">For</SPAN> lCount = 1<SPAN style="color:#00007F">To</SPAN> Len(Password) - 2<br> <SPAN style="color:#00007F">If</SPAN> (Mid(Password, lCount, 1) = Mid(Password, lCount + 1, 1)) And _<br> (Mid(Password, lCount + 1, 1) = Mid(Password, lCount + 2, 1))<SPAN style="color:#00007F">Then</SPAN><br> RptCount = RptCount + 1<br> <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">Next</SPAN> lCount<br> <SPAN style="color:#00007F">For</SPAN> lCount = 1<SPAN style="color:#00007F">To</SPAN> Len(Password)<br> <SPAN style="color:#00007F">If</SPAN> InStr(1, PrevPass, Mid(Password, lCount, 1)) = 0<SPAN style="color:#00007F">Then</SPAN><br> PrevCount = PrevCount + 1<br> <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">Next</SPAN> lCount<br> <SPAN style="color:#00007F">If</SPAN> (oMat1.Count >= 3) And (oMat2.Count >= 2) And (RptCount = 0) And (PrevCount >= 3)<SPAN style="color:#00007F">Then</SPAN><br> Range("A" & lr + 1).Value = Password<br> <SPAN style="color:#00007F">Else</SPAN><br> <SPAN style="color:#00007F">GoTo</SPAN> GenPass2<br> <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">With</SPAN><br> <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">Sub</SPAN><br></FONT>
Examples of generated passwords.
Excel Workbook |
---|
|
---|
| A |
---|
1 | Password List |
---|
2 | SW<=i"hmc%Gr |
---|
3 | D{r&zCRi&XM=[ |
---|
4 | 9;onX}v6b}7S |
---|
5 | |
---|
6 | ]GGc?\42W |
---|
7 | Lv9jD |
---|
8 | I*Ubvo#TwI`P |
---|
9 | LBG:&7}&ECO |
---|
10 | M9\S/y^PE |
---|
11 | jLgYo"4' |
---|
12 | @-!S^Tn( |
---|
13 | `KB/cxR)h |
---|
14 | LO4?)X0x*J |
---|
15 | sg:`9)#?k |
---|
16 | 7N8A%N4rXg |
---|
17 | @T(\G{+w[A/N5~ |
---|
18 | d~@OGb1HTmSI |
---|
19 | 6[O`tC= |
---|
20 | CsM2agZj0l4z |
---|
21 | &kDL,+1% |
---|
22 | SU5LggFug)\d" |
---|
23 | F:}lbHf;BIy |
---|
24 | ]A*2(I{S |
---|
25 | |5DF;P.Q{Uv |
---|
26 | Jb'hbO/6?j%Q |
---|
27 | l?|l`vsH,zkbF |
---|
28 | 00PG*:]p |
---|
29 | 2uD?i5K7sZD |
---|
30 | qXxQ@r991A |
---|
|
---|
Excel 2003