- ©«¤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-11-29
|
¦^´_ 9# ã´£³¡ªL
ÁÂÁ«e½ú
«á¾ÇÂǦ¹½d¨Ò¾Ç²ß°}¦C»P¦r¨å,«Ü¦hÁ٬ݤ£À´,¼È¾Ç²ß¤ß±o¦p¤U,½Ð«e½ú¦A«ü¾É
°õ¦æ«e:
°õ¦æµ²ªG:
Sub Get_Group()
Dim Arr, Brr, Q, xD1, xD2, A$, b$, T$, TT$, S$, i&, N&, R&
'¡ô«Å§iÅܼÆ:(Arr,Brr,Q,xD1,xD2)¬O³q¥Î«¬ÅܼÆ,(A,b,T,TT,S)¬O¦r¦êÅܼÆ,
'(i,N,R)¬Oªø¾ã¼ÆÅܼÆ
Arr = Range([´À¥Nªí!B2], [´À¥Nªí!C1].Cells(Rows.Count, 1).End(xlUp))
'¡ô¥OArr³o³q¥Î«¬ÅܼƬO ¤Gºû°}¦C,¥H´À¥Nªí[B2]¨ì CÄæ³Ì«á¦³¤º®eÀx¦s®æȱa¤J
Set xD1 = CreateObject("Scripting.Dictionary")
'¡ô¥OxD1³o³q¥Î«¬ÅܼƬO ¦r¨å
For i = 1 To UBound(Arr)
'¡ô³]¶¶°j°é!i±q1¨ì Arr°}¦CÁa¦V³Ì¤j¯Á¤Þ¦C¸¹
A = Arr(i, 1): b = Arr(i, 2): TT = ""
'¡ô¥OA³o¦r¦êÅܼƬO i°j°é¦C²Ä1ÄæArr°}¦CÈ,
'¥Ob³o¦r¦êÅܼƬO i°j°é¦C²Ä2ÄæArr°}¦CÈ,¥OTT³o¦r¦êÅܼƬO ªÅ¦r¤¸
If A <> "" And b <> "" Then
'¡ô¦pªGAÅܼƤ£¬O ªÅ¦r¤¸,¥BbÅܼƤ]¤£¬O ªÅ¦r¤¸??
T = xD1(A) & " " & xD1(b) & " " & A & " " & b
'¡ô¥OTÅܼƬO AÅܼƷíkey¬dxD1¦r¨åªºitemÈ,³s±µªÅ¥Õ¦r¤¸,
'³s±µbÅܼƷíkey¬dxD1¦r¨åªºitemÈ,³s±µªÅ¥Õ¦r¤¸,³s±µAÅܼÆ,
'³s±µªÅ¥Õ¦r¤¸,³Ì«á³s±µbÅܼƩҲզ¨ªº·s¦r¦ê
For Each Q In Split(T, " ")
'¡ô³]³v¶µ°j°é!¥OQ³o³q¥Î«¬ÅܼƬO ¥HªÅ¥Õ¦r¤¸¤Á³ÎTÅܼƪº¤@ºû°}¦C,¨ä¤¤¤@¤l
If InStr(TT, Q) = 0 Then TT = Trim(TT & " " & Q)
'¡ô¦pªGTTÅܼƦr¦ê¸Ì¨S¦³¥]§tQÅܼƦr¦ê!´N¥OTTÅܼƬO
'(¦Û¨³s±µ ªÅ¦r¤¸,¦A³s±µ QÅܼÆ)«á¥hÀY§ÀªÅ¥Õ¦r¤¸©Ò²Õ¦¨ªº·s¦r¦ê
Next
For Each Q In Split(TT, " ")
'¡ô³]³v¶µ°j°é!¥OQ³o³q¥Î«¬ÅܼƬO ¥HªÅ¥Õ¦r¤¸¤Á³ÎTTÅܼƪº¤@ºû°}¦C,¨ä¤¤¤@¤l
If Q <> "" Then xD1(Q) = TT
'¡ô¦pªGQÅܼƤ£¬O ªÅ¦r¤¸!´N¥OQÅܼƷíkey,item¬O TTÅܼƯǤJxD1¦r¨å¤¤
Next
End If
Next i
'¡ô§â©Ò¦³¦³¦å½tÃö«Yªº¤H³£µo¤@±i¤á¤f¦Wï
ReDim Brr(1 To UBound(Arr), 0)
'¡ô«Å§iBrr³o³q¥Î«¬ÅܼƬO¤Gºû°}¦C,Áa¦V½d³ò±q1¨ì ArrÁa¦V³Ì¤j¯Á¤Þ¦C¸¹,
'¾î¦V½d³ò±q0¨ì0
For i = 1 To UBound(Arr)
'¡ô³]¶¶°j°é!i±q1¨ì ArrÁa¦V³Ì¤j¯Á¤Þ¦C¸¹
Brr(i, 0) = xD1(Arr(i, 1))
'¡ô¥Oi°j°é¦C0¯Á¤Þ¸¹Äæ°}¦CȬO ¥Hi°j°é¦C²Ä1ÄæArr°}¦CȬdxD1¦r¨å±oitemÈ
Next i
[´À¥Nªí!D2].Resize(UBound(Arr)) = Brr
'¡ô¥O´À¥Nªí[D2]¦V¤UÂX®i Arr°}¦CÁa¦V³Ì¤j¯Á¤Þ¸¹¦C¼Æ,
'³o½d³òÀx¦s®æÈ¥HBrr°}¦Cȱa¤J
'------------------------------------------------------
Arr = Range([B2], Cells(Rows.Count, 2).End(xlUp))
'¡ô¥OArrÅܼƴ«¸Ë²{¥Î¤u§@ªí[B2]¨ì BÄæ³Ì«á¦³¤º®eÀx¦s®æÈ
Set xD2 = CreateObject("Scripting.Dictionary")
'¡ô¥OxD2³o³q¥Î«¬ÅܼƬO ¥t¤@Ó¦r¨å
For i = 1 To UBound(Arr)
'¡ô³]¶¶°j°é!i±q1¨ì ArrÁa¦V³Ì¤j¯Á¤Þ¦C¸¹
T = xD1(Arr(i, 1))
'¡ô¥OTÅܼƬO¥Hi°j°é¦C²Ä1ÄæArr°}¦CȬd xD1¦r¨å±oitemÈ
If T <> "" Then
'¡ô¦pªGTÅܼƤ£¬O ªÅ¦r¤¸?
S = xD2(T): Q = S
'¡ô¥OS³o¦r¦êÅܼƬO ¥HTÅܼƬd xD2¦r¨å±oitemÈ
'¥OQÅܼƬO SÅܼÆÈ
If S = "A" Then N = N + 1: Q = N
'¡ô¦pªGSÅܼƬO "A"¦r¤¸!´N¥ONÅܼƲ֥[1,¥OQÅܼƬO NÅܼÆÈ
If S = "" Then Q = "A"
'¡ô¦pªGSÅܼƬOªÅ¦r¤¸!´N¥OQÅܼƬO "A"¦r¤¸
xD2(T) = Q
'¡ô¥O¥HTÅܼƷíkey,item¬OQÅܼÆ,¯Ç¤JxD2¦r¨å
End If
Next
ReDim Brr(1 To UBound(Arr), 1)
'¡ô«Å§iBrr³o³q¥Î«¬ÅܼƬO¤Gºû°}¦C,Áa¦V½d³ò±q1¨ì ArrÁa¦V³Ì¤j¯Á¤Þ¦C¸¹,
'¾î¦V½d³ò±q0¨ì1
For i = 1 To UBound(Arr)
'¡ô³]¶¶°j°é!i±q1¨ì ArrÁa¦V³Ì¤j¯Á¤Þ¦C¸¹
T = xD1(Arr(i, 1))
'¡ô¥OTÅܼƬO i°j°é¦C²Ä1ÄæArr°}¦CȬd xD1¦r¨å±oitemÈ
Q = Val(xD2(T))
'¡ô¥OQÅܼƬO ¥HTÅܼƬd xD2¦r¨å±oitemÈÂন¼ÆÈ
If Q > 0 Then Brr(i, 0) = Q: Brr(i, 1) = T
'¡ô¦pªGQÅܼƤj©ó 0!´N¥Oi°j°é¦C0¯Á¤Þ¸¹ÄæBrr°}¦CȬO QÅܼÆ,
'¥Oi°j°é¦C²Ä1ÄæBrr°}¦CȬO TÅܼÆÈ
Next
[D2:E2].Resize(UBound(Arr)) = Brr
'¡ô¥O[D2:E2]¦V¤UÂX®iArr°}¦CÁa¦V¯Á¤Þ¦C¸¹¼Æ½d³òÀx¦s®æÈ,¥HBrr°}¦Cȱa¤J
End Sub |
|