- ©«¤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-3-15 10:34 ½s¿è
¦^´_ 1# yuras
¦^´_ 4# Hsieh
ÁÂÁ½׾Â,ÁÂÁ«e½ú
Âdzo©«¤µ¤Ñ«á¾Ç¦A½m²ß°}¦C»P¦r¨å,½Ð¦U¦ì«e½ú«ü±Ð
1.¨âÄæÃöÁä¦r¥H"|"²Å¸¹²Õ¦X¦¨key
2.Item¥H¦C¸¹¦b«e,®Ö½ÆÄæ¦b«á,¤¤¶¡¥H"|"²Å¸¹²Õ¦X
3.»ÝŪ¨úitem¤¤ªº¦C¸¹®É,¥HVAL(item)¤èªk«K¥i¨ú±o
¸ê®Æªí:
µ²ªGªí°õ¦æ«e:
°õ¦æµ²ªG:
Option Explicit
Sub Test()
Dim Brr, Crr, Y, i&, T$
'¡ô«Å§iÅܼÆ:(Brr,Crr,Y)¬O³q¥Î«¬ÅܼÆ,i¬Oªø¾ã¼Æ,T¬O¦r¦êÅܼÆ
Set Y = CreateObject("Scripting.Dictionary")
'¡ô¥OY³o³q¥Î«¬ÅܼƬO ¦r¨å
Brr = Sheets("1").UsedRange
'¡ô¥OBrr³o³q¥Î«¬ÅܼƬO¤Gºû°}¦C,¥Hªí1¦³¨Ï¥ÎÀx¦s®æȱa¤J
Crr = Sheets("2").UsedRange
'¡ô¥OCrr³o³q¥Î«¬ÅܼƬO¤Gºû°}¦C,¥Hªí2¦³¨Ï¥ÎÀx¦s®æȱa¤J
For i = 2 To UBound(Crr)
'¡ô³]¶¶°j°é!i±q2¨ì CrrÁa¦V³Ì¤j¯Á¤Þ¦C¸¹
T = Crr(i, 1) & "|" & Trim(Crr(i, 2))
'¡ô¥OT³o¦r¦êÅܼƬO i°j°é¦C²Ä1ÄæCrr°}¦Cȳs±µ"|"¦A³s±µ
'i°j°é¦C²Ä2ÄæCrr°}¦CÈ¥h°£ÀY§ÀªÅ¥Õ¦r¤¸«áªº·s¦r¦ê
If Y.Exists(T) Then
'¡ô¦pªG¬dY¦r¨å¸Ì¦³ TÅܼƳokey?
If Split(Y(T), "|")(1) <> Trim(Crr(i, 3)) Then
'¡ô¦pªG¥HTÅܼƬdY¦r¨å¦^¶ÇitemÈ¥Î"|"¤À³Î«áªº¤@ºû°}¦C1¯Á¤Þ¸¹
'°}¦C¤l ¤£¦P©ó i°j°é¼Æ²Ä3ÄæCrr°}¦CÈ¥h°£ÀY§ÀªÅ¥Õ¦r¤¸ªº·s¦r¦ê?
MsgBox T & " ¸ê®Æ¦³½Æ¿ï,½Ð½T»{": Exit Sub
'¡ô¸õ¥X´£¥Üµ¡~~ :«ö½T»{«áµ²§ôµ{¦¡°õ¦æ
End If
Else
Y(T) = i & "|" & Trim(Crr(i, 3))
'¡ô§_«h´N¥HTÅܼƬ°key,item¬O i°j°é¼Æ³s±µ"|"¦A³s±µ
'i°j°é¼Æ²Ä3ÄæCrr¦CÈ¥h°£ÀY§ÀªÅ¥Õ¦r¤¸ªº·s¦r¦ê«áªº·s¦r¦ê,
'¯Ç¤JY¦r¨å
End If
Next
For i = 2 To UBound(Brr)
'¡ô³]¶¶°j°é!i±q2¨ì BrrÁa¦V³Ì¤j¯Á¤Þ¦C¸¹
T = Trim(Brr(i, 2)) & "|" & Brr(i, 1)
'¡ô¥OT³o¦r¦êÅܼƬO i°j°é¦C²Ä2ÄæBrr°}¦CÈ¥h°£ÀY§ÀªÅ¥Õ¦r¤¸«áªº·s¦r¦ê
'³s±µ"|"¦A³s±µ i°j°é¦C²Ä1ÄæBrr°}¦CÈ
Brr(i, 4) = Crr(Val((Y(T))), 3)
'¡ô¥Oi°j°é¦C²Ä4ÄæBrr°}¦CȬO Val((Y(T)))¦C²Ä3ÄæCrr°}¦CÈ,
'Val((Y(T)))¦C:¥HTÅܼƬdY¦r¨å¦^¶ÇªºitemÈÂà¤Æ¬°¼ÆÈ ¦C
Next
[1!G1].Resize(UBound(Brr), 4) = Brr
'¡ô¥O¦W1ªº¤u§@ªí±q [G1]¶}©lÂX®i¦V¤U Brr°}¦CÁa¦V³Ì¤j¯Á¤Þ¦C¸¹¼Æ¦C,
'¦V¥kÂX®i 4Äæ,³oÂX®i½d³òªºÀx¦s®æ¥HBrr°}¦Cȱa¤J
End Sub |
|