- ©«¤l
- 1446
- ¥DÃD
- 40
- ºëµØ
- 0
- ¿n¤À
- 1470
- ÂI¦W
- 0
- §@·~¨t²Î
- Windows 7
- ³nÅ骩¥»
- Excel 2010 & 2016
- ¾\ŪÅv
- 50
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ¥xÆW
- µù¥U®É¶¡
- 2020-7-15
- ³Ì«áµn¿ý
- 2024-10-21
|
¥»©«³Ì«á¥Ñ Andy2483 ©ó 2023-2-9 08:56 ½s¿è
¦^´_ 7# ymes
ÁÂÁ«e½ú¦A¦^´_
1.«á¾Ç½Æ²ß¤F¤@¤U,°µ¤Fµù¸Ñ,½Ð«e½ú°Ñ¦Ò
2.¦pªG¶]¹D¼Æ,¨C¯Z¤H¼Æ,¦P¯Z¤£¦P¹D³o¨Ç±ø¥ó¾ÉPÀH¾÷²Õ¦XµL¸Ñ!! ¸Ó¦p¦ó³]p¤~¯à§P©wµL¸Ñ?? ¨Ã¸õ¥X "µL¸Ñ" ´£µøµ¡«áµ²§ôµ{§Ç??
¨Ò¦p:¨C¯Z¤H¼Æ4¤H·|¾ÉPµL¸Ñ,½Ð«e½úÌ«ü¾É,ÁÂÁÂ
Option Explicit
Sub TEST_1()
Dim Drr, Brr, Crr, Y, ¶Ã¼Æ&, ¤H¼Æ&, ¹D¼Æ&, ²Õ¼Æ&, °õ¦æ¼Æ&, ¶]¹D¼Æ&, i&
Dim ¶µ¥Ø$, Arr(1 To 1000, 1 To 3), n&, m&
'¡ô«Å§iÅܼÆ:(Drr, Brr, Crr, Y)¬O³q¥Î«¬ÅܼÆ,¶µ¥Ø ¬O¦r¦êÅܼÆ,Arr¬O¤Gºû°}¦C,
'¨ä¥L¬Oªø¾ã¼ÆÅܼÆ
¶µ¥Ø = Split(ActiveSheet.Name, "(")(0)
'¡ô¥O ¶µ¥Ø ³o¦r¦êÅܼƬO ¥H"("²Å¸¹ ±N¤u§@ªí¦W¤À³Î¦¨¤@ºû°}¦C¨ú0¯Á¤Þ¸¹ªº¦r¦ê
¶]¹D¼Æ = [A3].End(xlDown).Row - 2
'¡ô¥O (¶]¹D¼Æ) ³oªø¾ã¼ÆÅܼƬO ±q[A3]Àx¦s®æ©¹¤U§ä¨ìªÅ®æªº«e¤@®æ¦C¸¹ - 2
Drr = Range([³ø¦Wªí!C2], [³ø¦Wªí!A65536].End(3))
'¡ô¥O Drr³o³q¥Î«¬ÅÜ¼Æ ¬O¤Gºû°}¦C,¥H³ø¦Wªí[C2]¨ìAÄæ³Ì«á¤@Ó¦³¤º®eÀx¦s®æÈˤJ
For i = 1 To UBound(Drr)
'¡ô³]¶¶°j°é!±q1¨ì Drr°}¦CÁa¦V³Ì«á¯Á¤Þ¸¹
If Drr(i, 3) Like ¶µ¥Ø & "*" Then
'¡ô¦pªGi°j°é¼Æ²Ä3ÄæDrr°}¦CȬO (¶µ¥Ø)ÅÜ¼Æ ¶}ÀYªº¦r¦ê??
n = n + 1
'¡ô¥On³oªø¾ã¼ÆÅÜ¼Æ ²Ö¥[1
Arr(n, 1) = Drr(i, 1): Arr(n, 2) = Drr(i, 2): Arr(n, 3) = Drr(i, 3)
'¡ô¥OnÅܼƦC²Ä1ÄæArr°}¦CȬO iÅܼƦC²Ä1ÄæDrr°}¦CÈ,~~¨Ì¦¹Ãþ±À
End If
If InStr(Cells(i, 1), ¶µ¥Ø) Then Cells(i, 2).Resize(1, 2).ClearContents: m = m + 1
'¡ô¦pªG¤u§@ªíiÅܼƦC²Ä1ÄæÀx¦s®æÈ ¥]§t¤F(¶µ¥Ø)ÅܼƦr¦ê!´N²M°£¥k°¼¨âÀx¦s®æªº¤º®e,
'¥Om³oªø¾ã¼ÆÅܼƲ֥[1
Next
If n = 0 Then
'¡ô¦pªGnÅܼƬO 0?
MsgBox "¨S¦³¦W³æ!µLªk°õ¦æ": Exit Sub
'¡ô¸õ¥X´£¥Üµ¡~"¨S¦³¦W³æ!µLªk°õ¦æ"~,¤§«áµ²§ôµ{¦¡°õ¦æ
End If
If m < n Then
'¡ô¦pªG mÅܼƤp©ó nÅܼÆ?
MsgBox "²Õ¼Æªí®æ¤£°÷!µLªk°õ¦æ": Exit Sub
'¡ô¸õ¥X´£¥Üµ¡~"²Õ¼Æªí®æ¤£°÷!µLªk°õ¦æ"~,¤§«áµ²§ôµ{¦¡°õ¦æ
End If
[L:N].ClearContents: [L1].Resize(n, 3) = Arr
'¡ô¥O[L:N]³o3ÄæÀx¦s®æ¤º®e²M°£ :¥O[L1]ÂX®i¦V¤UnÅܼƦC,¦V¥kÂX®i3Ä檺½d³òÀx¦s®æ¥HArr°}¦CÈˤJ
¤H¼Æ = n: ReDim Brr(¶]¹D¼Æ - 1, 1)
'¡ô¥O ¤H¼Æ³oªø¾ã¼ÆÅܼƬO nÅܼÆÈ: «Å§iBrr°}¦C¤j¤p(Áa¦V±q0¨ì ¶]¹D¼Æ-1,¾î¦V±q0¨ì 1)
Head:
Set Y = CreateObject("Scripting.Dictionary")
'¡ô¥OY¬O ¦r¨å
Do While °õ¦æ¼Æ < ¤H¼Æ
'¡ô³]±ø¥ó°j°é:·í (°õ¦æ¼Æ)ÅÜ¼Æ < (¤H¼Æ)ÅܼÆ!´NÄ~Äò°õ¦æ!
Randomize: ¶Ã¼Æ = Rnd() * 10000 Mod ¤H¼Æ + 1
'¡ô¥O ¶Ã¼Æ³oªø¾ã¼ÆÅܼƬO 1 ¨ì (¤H¼Æ)ÅܼƪºRnd()¶Ã¼ÆÈ
If Y.Exists(¶Ã¼Æ) = Empty Then
'¡ô¦pªG²£¥Íªº(¶Ã¼Æ)ÅܼÆȨS¦³¦bY¦r¨å¸Ì?
°õ¦æ¼Æ = °õ¦æ¼Æ + 1
'¡ô¥O(°õ¦æ¼Æ)³oªø¾ã¼ÆÅÜ¼Æ ²Ö¥[1
Y(¶Ã¼Æ) = ""
'¡ô¥O(¶Ã¼Æ)ÅܼƷíkey,item¬OªÅ¦r¤¸©ñ¤JY¦r¨å
¹D¼Æ = °õ¦æ¼Æ Mod ¶]¹D¼Æ
'¡ô¥O(¹D¼Æ)³oªø¾ã¼ÆÅܼƬO (°õ¦æ¼Æ) °£ (¶]¹D¼Æ) ªº¾l¼Æ
Y(Arr(¶Ã¼Æ, 1) & "|" & ¹D¼Æ) = ""
'¡ô¥O(¶Ã¼Æ)ÅܼƦC²Ä1ÄæArr°}¦CÈ ³s±µ "|" ¦A³s±µ (¹D¼Æ)Åܼƪº²Õ¦X¦r¦ê·íkey,item¬OªÅ¦r¤¸©ñ¤JY¦r¨å
²Õ¼Æ = IIf(¹D¼Æ, °õ¦æ¼Æ \ ¶]¹D¼Æ + 1, °õ¦æ¼Æ \ ¶]¹D¼Æ)
'¡ô¥O(²Õ¼Æ)³oªø¾ã¼ÆÅܼƬO ¥HIIf()§PÂ_ªº¦^¶ÇÈ,
'¦pªG(¹D¼Æ)ÅܼƤ£¬O0,´N¥O(²Õ¼Æ)ÅܼƬO (°õ¦æ¼Æ)ÅÜ¼Æ °£ (¶]¹D¼Æ)ªº°Ó¨ú¾ã¼Æ«á + 1
'¦pªG(¹D¼Æ)ÅܼƬO0,´N¥O(²Õ¼Æ)ÅܼƬO (°õ¦æ¼Æ)ÅÜ¼Æ °£ (¶]¹D¼Æ)ªº°Ó¨ú¾ã¼Æ
Y(Arr(¶Ã¼Æ, 1) & "/" & ²Õ¼Æ) = ""
'¡ô¥O(¶Ã¼Æ)¦C²Ä1ÄæArr°}¦CÈ ³s±µ "/" ¦A³s±µ (²Õ¼Æ)Åܼƪº²Õ¦X¦r¦ê·íkey,item¬OªÅ¦r¤¸©ñ¤JY¦r¨å
Crr = Y(²Õ¼Æ & "/²Õ")
'¡ô¥OCrr³o³q¥Î«¬ÅܼƬO ¥H(²Õ¼Æ)ÅÜ¼Æ ³s±µ "/²Õ"¦¨ªº²Õ¦X¦r¦ê·íkey,¬dY¦r¨å±o¨ìªºitem
If Not IsArray(Crr) Then
'¡ô¦pªGCrrÅܼƤ£¬O°}¦C?
Crr = Brr
'¡ô¥OCrr ¬O Brr°}¦C
End If
¹D¼Æ = IIf(¹D¼Æ, ¹D¼Æ, ¶]¹D¼Æ)
'¡ô¥O(¹D¼Æ)ÅܼƬO ¥HIIf()§PÂ_ªº¦^¶ÇÈ,
'¦pªG(¹D¼Æ)ÅܼƤ£¬O0!´N¥O(¹D¼Æ)ÅܼƬO (¹D¼Æ)ÅܼÆ
'¦pªG(¹D¼Æ)ÅܼƬO0!´N¥O(¹D¼Æ)ÅܼƬO (¶]¹D¼Æ)ÅܼÆ
Crr(¹D¼Æ - 1, 0) = Arr(¶Ã¼Æ, 1): Crr(¹D¼Æ - 1, 1) = Arr(¶Ã¼Æ, 2)
'¡ô¥O(¹D¼Æ)ÅܼÆ-1¯Á¤Þ¸¹¦C²Ä0¯Á¤Þ¸¹ÄæCrr°}¦CȬO (¶Ã¼Æ)ÅܼƦC²Ä1ÄæArr°}¦CÈ
'¡ô¥O(¹D¼Æ)ÅܼÆ-1¯Á¤Þ¸¹¦C²Ä1¯Á¤Þ¸¹ÄæCrr°}¦CȬO (¶Ã¼Æ)ÅܼƦC²Ä2ÄæArr°}¦CÈ
Y(²Õ¼Æ & "/²Õ") = Crr
'¡ô¥O¥H(²Õ¼Æ)ÅܼƳs±µ "/²Õ" ªº²Õ¦X¦r¦ê·íkey,item¬O Crr°}¦C,©ñ¤JY¦r¨å
'¦pªG¸Ókey¤w¦s¦bY°}¦C!´N¨ú¥N¨äitem
End If
If (Y.Count - ²Õ¼Æ) Mod °õ¦æ¼Æ Then
'¡ô¦pªG(Y¦r¨åkey¼Æ¶q - (²Õ¼Æ)ÅܼÆ) °£ (°õ¦æ¼Æ)Åܼƪº¾l¼Æ¤£¬O0?
²Õ¼Æ = 0
'¡ô¥O(²Õ¼Æ)ÅܼƬO 0
°õ¦æ¼Æ = 0
'¡ô¥O(°õ¦æ¼Æ)ÅܼƬO 0
GoTo Head
'¡ô¸õ¨ì Head¼Ð¥Ü³BÄ~Äò°õ¦æ
End If
Loop
'¡ô¸õ¨ì Do ¦ì¸mÄ~Äò°õ¦æ
For i = 1 To ²Õ¼Æ
'¡ô³]¶¶°j°é!i±q1¨ì (²Õ¼Æ)ÅܼÆ
[B3].Item((i - 1) * (¶]¹D¼Æ + 3) + 1, 1).Resize(¶]¹D¼Æ, 2) = Y(i & "/²Õ")
'¡ô[B3]Àx¦s®æÂX®i¦V¤U(¶]¹D¼Æ)ÅܼƦC,¦V¥kÂX®i2Äæ½d³òÀx¦s®æ¥H °}¦CÈ Ë¤J,
'°}¦CȬO:¥H i°j°é¼Æ ³s±µ "/²Õ"ªº²Õ¦X¦r¦ê·íkey,¬dY¦r¨å±o¨ìªºitem
Next
End Sub |
|