- ©«¤l
- 1447
- ¥DÃD
- 40
- ºëµØ
- 0
- ¿n¤À
- 1471
- ÂI¦W
- 0
- §@·~¨t²Î
- Windows 7
- ³nÅ骩¥»
- Excel 2010 & 2016
- ¾\ŪÅv
- 50
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ¥xÆW
- µù¥U®É¶¡
- 2020-7-15
- ³Ì«áµn¿ý
- 2024-12-5
|
¦^´_ 19# ã´£³¡ªL
ÁÂÁ«e½ú«ü¾É,«á¾Ç¾q¶w,³o¤ÓÃø¤F
«á¾Çµ{«×¥u¯à¤j·§ª¾¹Dµ{¦¡½X·N«ä,¨äÅÞ¿è·N¸q¤ÓÃø¤F,«á¾ÇÄ~Äò¾Ç²ß,§Æ±æ¦³¤Ñ¯à¶}¬¬ÝÀ´
Sub B_¶}©l¤À²Õ()
Dim Arr, xD, R&, N&, i&, T$, TC$, TV$, X%, V%, Nx%, j%
'¡ô«Å§iÅܼÆ!(Arr,xD)¬O³q¥Î«¬ÅܼÆ,(R,N,i)¬Oªø¾ã¼ÆÅܼÆ,(T,TC,TV)¬O¦r¦êÅܼÆ,¨ä¥L¬Oµu¾ã¼ÆÅܼÆ
[k6] = ""
'¡ô¥O[K6]Àx¦s®æȬOªÅ¦r¤¸
Call «¸m¸ê®Æ
'¡ô°õ¦æ(«¸m¸ê®Æ)°Æµ{¦¡
R = [m65536].End(3).Row
'¡ô¥OR³oªø¾ã¼ÆÅܼƬO MÄæ³Ì«á¤@Ó¦³¤º®eÀx¦s®æ¦C¸¹
If R < 2 Then MsgBox "¡¯©|¥¼¸ü¤J¸ê®Æ¡I¡@": Exit Sub
'¡ô¦pªGRÅÜ¼Æ < 2 !´N¸õ¥X´£¥Üµ¡~~,«ö½T»{«á§Yµ²§ôµ{¦¡°õ¦æ
Set xD = CreateObject("Scripting.Dictionary")
'¡ô¥OxD¬O ¦r¨å
Re_Try:
'¡ôµ{§Ç¦ì¸mÃѧO
Nx = Nx + 1
'¡ô¥ONx³oµu¾ã¼ÆÅܼƲ֥[ 1
If Nx > 10 Then MsgBox "¡¯°õ¦æ¤À²Õ¦h¦¸µLµ²ªG¡I½Ð«¸Õ©ÎÀˬd¸ê®Æ¬O§_¥¿½T¡I¡@": Exit Sub
'¡ô¦pªGNxÅÜ¼Æ > 10!´N¸õ¥X´£µøµ¡~~,«ö½T»{«á§Yµ²§ôµ{¦¡°õ¦æ
xD.removeall
'¡ô¥OxD¦r¨å²MªÅ
TC = Left(123456789, [k3])
'¡ô¥OTC³o¦r¦êÅܼƬO 123456789¦r¦êªº¥ª°¼ [k3]ÈÓ¦r
For j = 1 To [k5] - 1: xD(j) = TC: Next
'¡ô³]¶¶°j°éj±q1¨ì [k3]È(¶]¹D¼Æ)-1 :¥O¥HjÅܼƷíkey,item¬O TCÅܼÆ,¯Ç¤J xD¦r¨å¸Ì
xD(j) = Left(TC, [k4] - ([k5] - 1) * [k3])
'¡ô¥OjÅܼƷíkey,item¬O TCÅܼƥª°¼ªº [k4] - ([k5] - 1) * [k3]Ó¦r
'=¤H¼Æ - (²Õ¼Æ - 1)¼¤W ¶]¹D¼Æ
Randomize
'¡ô¤£©T©w¶Ã¼Æªì©lÈ
Arr = Range("m2:p" & R)
'¡ô¥OArr³o³q¥Î«¬ÅܼƬO¤Gºû°}¦C,¥H[M2]¨ì PÄæ²Ä RÅܼƦC½d³ò,
'³o½d³òÀx¦s®æÈˤJ°}¦C¤¤
For i = R - 1 To 1 Step -1
'¡ô³]°f°j°éi±q RÅܼÆ-1 ¨ì1 ,¥O¨C¦¸°j°éÅýi -1
T = Arr(i, 1)
'¡ô¥OT³o¦r¦êÅܼƬO iÅܼƦC²Ä1ÄæArr°}¦CÈ
N = 0
'¡ô¥ON³oªø¾ã¼ÆÅܼƬO 0
V = Arr(i, 4)
'¡ô¥OV³oµu¾ã¼ÆÅܼƬO iÅܼƦC²Ä4ÄæArr°}¦CÈ
TV = xD(V)
'¡ô¥OTV³o¦r¦êÅܼƬO ¥HVÅܼƷíkey¬dxD¦r¨å¦^¶ÇªºitemÈ
Do
'¡ô³]µL°j°é! »Ýn·Q¿ìªk¸õ¥X°j°é!
X = Val(Mid(TV, Int(Rnd * Len(TV)) + 1, 1))
'¡ô¥OX³oµu¾ã¼ÆÅܼƬO Val¨ç¦¡¦^¶Çªº¼Æ¦r,
'¨ç¦¡¤º®e:TVÅܼƱq Int(Rnd * Len(TV)) + 1 Ó¦r¶}©l,¨ú1Ó¦r
'¶Ã¼Æ ¼ TVÅܼƪº¦r¤¸¼Æ«á,¥h°£¤p¼Æ,³Ì«á +1
If xD(T & "/" & X) = 0 Then Exit Do
'¡ô¦pªG¥H TÅܼƳs±µ "/" ²Å¸¹¦A³s±µ XÅܼƷíkey¬d xD¦r¨å¦^¶ÇitemȬO 0??
'¦pªG¬O 0,´N¸õ¥X°j°é
N = N + 1
'¡ô¥ONÅܼƲ֥[ 1
If N >= 200000 Then GoTo Re_Try
'¡ô¦pªGNÅÜ¼Æ N >= 200000!,´N¸õ¨ì Re_Try¼Ð¥Ü¦ì¸mÄ~Äò°õ¦æ
Loop
xD(V) = Replace(TV, X, "")
'¡ô¥O¥HVÅܼƷíkey,item¬O(TVÅÜ¼Æ ±NXÅܼƥHªÅ¦r¤¸¸m´«)«áªº¦r¦ê,¯Ç¤JxD¦r¨å
xD(T & "/" & X) = 1
'¡ô¥O¥HTÅܼƳs±µ "/" ¦A³s±µ XÅܼƪº·s¦r¦ê·íkey,item¬O 1,¯Ç¤JxD¦r¨å
Arr(i, 3) = X
'¡ô¥Oi°j°é¦C²Ä3ÄæArr°}¦CȬO XÅܼÆ
Next i
With [m2].Resize(R - 1, 4)
'¡ô¥H¤U¬O[M2]ÂX®i¦V¤U R - 1¦C,¦V¥k 4Äæ½d³òÀx¦s®æªºµ{§Ç
.Value = Arr
'¡ô¥O³o½d³òÀx¦s®æÈ¥HArr°}¦CÈˤJ
.Sort Key1:=.Item(4), Order1:=xlAscending, _
Key2:=.Item(3), Order2:=xlAscending, Header:=xlNo
'¡ô¥O¸ê®Æ¥HPÄæ°µ¨S¦³¼ÐÃD¦Cªº¶¶±Æ§Ç,¦P®É°µ²Ä¤G¼hOÄ涶±Æ§Ç
End With
Application.ScreenUpdating = True: [k6] = "OK"
'¡ô¥O¿Ã¹õ«ì´_ÅܤÆ: ¥O[k6] Àx¦s®æȬO "OK" ¦r¦ê
MsgBox "¡ã¤À²Õ§¹¦¨¡ã¡@"
'¡ô¸õ¥X´£¥Üµ¡~~
End Sub |
|