- ©«¤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-11-28
|
ÁÂÁ½׾Â,ÁÂÁ¦U¦ì«e½ú
«á¾ÇÂǦ¹©«½m²ß°}¦C»P¦r¨å,¾Ç²ß¤è®×¦p¤U,½Ð¦U¦ì«e½ú«ü±Ð
Option Explicit
Sub TEST()
Dim Brr, Crr, Y, i&, T1$, T2$
'¡ô«Å§iÅܼÆ
Set Y = CreateObject("Scripting.Dictionary")
'¡ô¥OYÅܼƬO ¦r¨å
Brr = Range([B2], [A65536].End(3))
'¡ô¥OBrrÅܼƬO¤Gºû°}¦C,¥H[B2]¨ìAÄæ³Ì«á¤@¦³¤º®eªºÀx¦s®æȱa¤J
For i = 1 To UBound(Brr)
'¡ô³]¶¶°j°é
T1 = Brr(i, 1): T2 = Brr(i, 2)
'¡ô¥OÅܼƸˤJ°j°é°}¦CÈ,¥i¥H©w¸qȪº«¬ºA,¤]¥iÁYµuµ{¦¡½X
If T1 = "" Or T2 = "" Then GoTo i01
'¡ô¦pªGT1ÅܼƬOªÅªº©Î T1ÅܼƬOªÅªº?´N¸õ¨ì¼Ð¥Üi01¦ì¸mÄ~Äò°õ¦æ
If Y(T1) = "" Then Y(T1) = T2: GoTo i01
'¡ô¦pªG¥HT1ÅܼƬdY¦r¨å±oitemȬO ªÅªº?
'¬O´N¥OT1ÅܼƷíkey,item¬OT2ÅܼÆ,¯Ç¤JY¦r¨å¤¤,¸õ¨ì¼Ð¥Üi01¦ì¸mÄ~Äò°õ¦æ
If InStr("," & Y(T1) & ",", "," & T2 & ",") = 0 Then
'¡ô¦pªG¥HT1Åܼƴ£¨úY¦r¨å¤¤itemȦ³¨S¦³¥]§t T2ÅܼÆ?
'InStr()¤¤ªº¤¸¯À³£¥H³r¸¹¥]§¨«á¦A§PÂ_,°§C¥©¦Xªº·N¥~¾÷²v
Y(T1) = Y(T1) & "," & T2
'¡ô¥OT1ÅܼƦbY¦r¨å¤¤ªºitemȳs±µT2ÅܼÆ,¤¤¶¡¥H³r¸¹¹j¶}
End If
i01: Next
Brr = Range([D2], [D65536].End(3))
'¡ô¥OBrrÅܼƬO¤Gºû°}¦C,´«¸Ë[B2]¨ìAÄæ³Ì«á¤@¦³¤º®eªºÀx¦s®æÈ
ReDim Crr(1 To UBound(Brr), 1 To 1)
'¡ô¥OCrrÅܼƬO ¤GºûªÅ°}¦C,Áa¦V½d³ò¦PBrr°}¦C,¾î¦V1~1
For i = 1 To UBound(Brr)
'¡ô³]¶¶°j°é
Crr(i, 1) = Y(Brr(i, 1))
'¡ô¥OCrr°}¦CȬO Brr°}¦CȬdY¦r¨åªºitemÈ
Next
[E2:E65536].ClearContents
'¡ô¥OÀx¦s®æµ²ªG²M°£
[E2].Resize(UBound(Crr)) = Crr
'¡ô¥O±q[E2]Àx¦s®æ¶}©l¼g¤JCrr°}¦CÈ
Set Y = Nothing: Erase Brr, Crr
'¡ô¥OÄÀ©ñÅܼÆ
End Sub |
|