- ©«¤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-5-11 09:30 ½s¿è
¦^´_ 14# gaishutsusuru
¦^´_ 6# ã´£³¡ªL
ÁÂÁ«e½úµoªí¦¹¥DÃD»P½d¨Ò
ÁÂÁ 㴣³¡ªL«e½ú«ü¾É
«á¾ÇÂǦ¹©«¾Ç²ß«e½úªº¤è®×,¤è®×¾Ç²ß¤ß±oµù¸Ñ¦p¤U,½Ð«e½ú¦A«ü¾É
¸ê®Æªí:
µ²ªGªí:
Sub TEST_A1()
Dim Arr, Brr, xD, xD2, M&, V&, R&, i&, j%, C%, Cn%, T$
'¡ô«Å§iÅܼÆ:(Arr,Brr,xD,xD2)¬O³q¥Î«¬ÅܼÆ,(M,V,R,i)¬Oªø¾ã¼Æ,
'(j,C,Cn)¬Oµu¾ã¼Æ,T¬O¦r¦êÅܼÆ
Set xD = CreateObject("Scripting.Dictionary")
Set xD2 = CreateObject("Scripting.Dictionary")
'¡ô¦U¥O(xD,xD2)¬O¦r¨å
Arr = Sheet1.[a1].CurrentRegion
'¡ô¥OArr³o³q¥Î«¬ÅܼƬO ¤Gºû°}¦C,¥Hªí1ªº[A1]¦ê¨ÃÁp«áÂX®i³Ì¤p¤è¥¿½d³ò,
'³Ì¤p¤è¥¿½d³òÀx¦s®æȱa¤JArr°}¦C¤¤
ReDim Brr(1 To UBound(Arr), 1 To 250)
'¡ô«Å§iBrr³o³q¥Î«¬ÅܼƬO¤GºûªÅ°}¦C,Áa¦V½d³ò:1¨ìArr°}¦C³Ì¤j¯Á¤Þ¦C¸¹,
'¾î¦V½d³ò±q1 ¨ì250
For i = 2 To UBound(Arr)
'¡ô³]¶¶°j°é!i±q2 ¨ìArr°}¦C³Ì¤j¯Á¤Þ¦C¸¹
M = Arr(i, 1): V = Arr(i, 6): T = ""
'¡ô¥OM³oªø¾ã¼ÆÅܼƬO i°j°é¦C²Ä1ÄæArr°}¦CÈ,
'¥OV³oªø¾ã¼ÆÅܼƬO i°j°é¦C²Ä6ÄæArr°}¦CÈ,¥OT³o¦r¦êÅܼƬO ªÅ¦r¤¸
For j = 2 To 5
'¡ô³]¶¶°j°é!j±q2 ¨ì5
T = T & "|" & Arr(i, j) '|¼t§O|¼t§O½s¸¹|¥N¸¹|¦WºÙ
'¡ô¥OTÅܼƬO¦Û¨³s±µ"|"²Å¸¹¦A³s±µ,
'³s±µi°j°é¦C²Äj°j°éÄæArr°}¦CÈ©Ò²Õ¦¨ªº·s¦r¦ê
Next
If Not xD.Exists(T) Then
'¡ô¦pªG¥HTÅܼƬdxD¦r¨å¸Ì¨S¦³³oÓkey?
Set xD(T) = CreateObject("Scripting.Dictionary")
'¡ô¥O¥HTÅܼƷíkey,item¬O¦r¨å,¯Ç¤JxD¦r¨å¸Ì (¦r¨å¤¤ªº¦r¨å)
R = R + 1
'¡ô¥OR³oªø¾ã¼ÆÅÜ¼Æ ²Ö¥[1 (PS:Rªø¾ã¼ÆÅܼƪºªì©lȬO0)
For j = 1 To 4
'¡ô³]¶¶°j°é!j±q1 ¨ì4
Brr(R + 1, j) = Arr(i, j + 1)
'¡ô¥O(RÅܼÆ+1)¦C²ÄjÅܼÆÄæBrr°}¦CȬO ,
'¬O i°j°é¦C²Ä(j°j°é+1)ÄæArr°}¦CÈ
If R = 1 Then Brr(1, j) = Arr(1, j + 1)
'¡ô¦pªGRÅܼƬO 1!´N¥O²Ä1¦Cj°j°éÄæBrr°}¦CȬO ,
'¬O ²Ä1¦C²Ä(jÅܼÆ+1)ÄæArr°}¦CÈ (³B²z¼ÐÃD¦C)
Next
End If
If M > xD2(T & -1) Then
'¡ô¦pªGMÅܼƤj©ó ¥H(TÅܼƳs±µ"-1"©Ò²Õ¦¨·s¦r¦ê)¬dxD2¦r¨å¦^¶ÇitemÈ
xD2(T & -1) = M '(¤ë¤é)
'¡ô¥O¥H(TÅܼƳs±µ"-1"©Ò²Õ¦¨·s¦r¦ê)·íkey,
'itemȬO MÅܼÆ,¯Ç¤JxD2¦r¨å
xD2(T) = V '(»ù®æ)
'¡ô¥O¥H TÅܼƷíkey,itemȬO VÅܼÆ,¯Ç¤JxD2¦r¨å
End If
xD(T)(V) = ""
'¡ô¥O¥H VÅܼÆ(»ù®æ)·íkey,item¬OªÅ¦r¤¸¯Ç¤J TÅܼƪº¦r¨å¸Ì
Next i
'-----------------------------------
For i = 1 To R
'¡ô³]¶¶°j°é!i±q2 ¨ìRÅܼÆ(¤l¦r¨åªº¼Æ¶q)
T = xD.keys()(i - 1)
'¡ô¥OTÅܼƬO xD¦r¨å¸Ìªº²Ä(iÅܼÆ-1)¯Á¤Þ¸¹key
V = xD2(T)
'¡ô¥OVÅܼƬO TÅܼƬdxD2¦r¨å¦^¶ÇitemÈ(»ù®æ)
Brr(i + 1, 5) = V
'¡ô¥O(i°j°é+1)¦C²Ä5ÄæBrr°}¦CȬO VÅܼÆ
xD(T).Remove V
'¡ô¥OTÅܼƤl¦r¨å¸Ìªº VÅܼÆkey²¾°£
Cn = xD(T).Count
'¡ô¥OCn³oµu¾ã¼ÆÅܼƬO TÅܼƤl¦r¨å¸Ìkeyªº¼Æ¶q
If Cn > C Then C = Cn
'¡ô¦pªGCnÅܼƤj©óC³oµu¾ã¼ÆÅܼÆ!´N¥OCÅܼƬO CnÅܼÆ
For j = 1 To Cn
'¡ô³]¶¶°j°é!j±q1 ¨ìCnÅܼÆ
Brr(i + 1, j + 5) = Application.Large(xD(T).keys, j)
'¡ô¥O¾ú¥v»ù¥ª¦Ü¥k¥Ñ¤j¨ì¤p¼g¤JBrr°}¦C¸Ì
Next j
Next i
For j = 1 To C: Brr(1, j + 5) = "¾ú¥v»ù" & j: Next
'¡ô¥O³]¶¶°j°é³B²z ¾ú¥v»ù ªº¼ÐÃD¦C
Brr(1, 5) = "²{¦æ»ù"
'¡ô¼ÐÃD¦Cªº²{¦æ»ù©ïÀY
'---------------------------------
Sheet2.UsedRange.ClearContents
'¡ô¥Oµ²ªGªí¸ê®Æ²M°£¤º®e
Sheet2.[a1].Resize(R + 1, C + 5) = Brr
'¡ô¥OBrr°}¦Cȼg¤Jµ²ªGªí[A1]¶}©lªººë½T½d³ò
End Sub |
|