- ©«¤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-13 10:42 ½s¿è
¦^´_ 24# Andy2483
ÁÂÁ½׾Â,ÁÂÁ¦U¦ì«e½ú
¤µ¤Ñ½Æ²ß¦¹ÃD,µo²{Âöº|»PÂØz,¤ß±oµù¸Ñ¦p¤U
Option Explicit
Sub TEST_1()
Dim Brr, Crr, Y, T$, Z$, j%, V%, i&
'¡ô«Å§iÅܼÆ:(Brr,Crr,Y)¬O³q¥Î«¬ÅܼÆ,(T,Z)¬O¦r¦êÅܼÆ,
'(j,V)¬Oµu¾ã¼ÆÅܼÆ,i¬Oªø¾ã¼ÆÅܼÆ
Set Y = CreateObject("Scripting.Dictionary")
'¡ô¥OY³o³q¥Î«¬ÅܼƬO ¦r¨å
Brr = Range([B2], Cells(Rows.Count, "A").End(3))
'¡ô¥OBrr¬O¤Gºû°}¦C,¥H[B2]¨ì AÄæ³Ì«á¦³¤º®eÀx¦s®æ,³o¨â®æ¤§¶¡©Ò¦³Àx¦s®æȱa¤J
Crr = Range([E2], Cells(Rows.Count, "E").End(3))
'¡ô¥OBrr¬O¤Gºû°}¦C,¥H[E2]¨ì EÄæ³Ì«á¦³¤º®eÀx¦s®æ,³o¨â®æ¤§¶¡©Ò¦³Àx¦s®æȱa¤J
For i = 1 To UBound(Brr)
'¡ô³]¶¶°j°é!i±q1 ¨ìBrr°}¦CÁa¦V³Ì¤j¯Á¤Þ¦C¸¹
T = Trim(Brr(i, 1)): If T = "" Then GoTo i01
'¡ô¥OT³o¦r¦êÅܼƬOi°j°é¦C²Ä1ÄæBrr°}¦CÈ¥h°£«e«áªÅ¥Õ¦r¤¸ÅSªº·s¦r:
'¦pªGTÅܼƬOªÅ¦r¤¸!´N¸õ¨ì i01¦ì¸mÄ~Äò°õ¦æ
V = Len(T)
'¡ô¥OV³oµu¾ã¼ÆÅܼƬO TÅܼƪº¦r¤¸¼Æ
For j = V To 1 Step -1
'¡ô³]¶¶°j°é!j±qVÅܼƨì 1,¥O¨CÓ°j°éj³£n-1
If Mid(T, j, 1) <> "0" Then
'¡ô¦pªGTÅܼƱqjÅܼƶ}©l¨ú1Ó¦rªº¦r¤¸¤£¬O"0"
Z = Mid(T, j + 1)
'¡ô¥OZ³o¦r¦êÅܼƬO TÅܼƱqj+1Ó¦r¶}©l¨ì ³Ì«á¦r¤§¶¡ªº¦r¦ê
Exit For
'¡ô¸õ¥Xj°j°é
End If
Next
T = Replace(UCase(Trim(Brr(i, 1))), "0", "") & Z
'¡ô¥OTÅܼƬO i°j°é¦C²Ä1ÄæBrr°}¦CÈ ¥h°£«e«áªÅ¥Õ¦r¤¸,¸gÂà¤Æ^¤å¦r¥À¬°¤j¼g,
'¦A±N0¸m´«¬°ªÅ¦r¤¸,³Ì«á³s±µZÅÜ¼Æ ²Õ¦¨·sªº¦r¦êÅܼÆ
If Y.Exists(T) = Empty Then
'¡ô¦pªG¥HTÅܼƬdY¦r¨å¸Ì¨S¦³³okey?
Y(T) = Brr(i, 2)
'¡ô¥O¥HTÅܼƷíkey,Item¬Oi°j°é¦C²Ä2ÄæBrr°}¦CÈ
ElseIf Y(T) <> Brr(i, 2) Then
'¡ô§_«h¦pªG¥HTÅܼƬdY¦r¨å©Ò¦^¶ÇȤ£¦P©ó i°j°é¦C²Ä2ÄæBrr°}¦CÈ??
MsgBox Brr(i, 1) & " ¥h0²¤Æ«áªº¸ê®ÆÄ榳¦P½s¸¹¤£¦P°Ó«~ºÃ¼{"
'¡ô¸õ¥X´£¥Üµ¡~~
Exit Sub
'¡ôµ²§ôµ{¦¡°õ¦æ
End If
i01:
Next
For i = 1 To UBound(Crr)
'¡ô³]¶¶°j°é!i±q1¨ì Crr°}¦CÁa¦V³Ì¤j¯Á¤Þ¦C¸¹
T = Trim(Crr(i, 1)): If T = "" Then GoTo i02
'¡ô¥OTÅܼƬO i°j°é¦C²Ä1Äæ°}¦CÈ¥h°£«e«áªÅ¥Õ¦r¤¸«áªº·s¦r¦ê,
'¦pªGTÅܼƬOªÅ¦r¤¸!´N¸õ¨ì i02¦ì¸mÄ~Äò°õ¦æ
V = Len(T)
'¡ô¥OV³oµu¾ã¼ÆÅܼƬO TÅܼƪº¦r¤¸¼Æ
For j = V To 1 Step -1
'¡ô³]¶¶°j°é!j±qVÅܼƨì 1,¥O¨CÓ°j°éj³£n-1
If Mid(T, j, 1) <> "0" Then
'¡ô¦pªGTÅܼƱqjÅܼƶ}©l¨ú1Ó¦rªº¦r¤¸¤£¬O"0"
Z = Mid(T, j + 1)
'¡ô¥OZ³o¦r¦êÅܼƬO TÅܼƱqj+1Ó¦r¶}©l¨ì ³Ì«á¦r¤§¶¡ªº¦r¦ê
Exit For
'¡ô¸õ¥Xj°j°é
End If
Next
T = Replace(UCase(Trim(Crr(i, 1))), "0", "") & Z
'¡ô¥OTÅܼƬO i°j°é¦C²Ä1ÄæBrr°}¦CÈ ¥h°£«e«áªÅ¥Õ¦r¤¸,¸gÂà¤Æ^¤å¦r¥À¬°¤j¼g,
'¦A±N0¸m´«¬°ªÅ¦r¤¸,³Ì«á³s±µZÅÜ¼Æ ²Õ¦¨·sªº¦r¦êÅܼÆ
Crr(i, 1) = Y(T)
'¡ô¥Oi°j°é¦C²Ä1ÄæCrr°}¦CȬO ¥HTÅܼƬdY¦r¨å©Ò¦^¶ÇªºItemÈ
i02:
Next
[I2].Resize(UBound(Crr), 1) = Crr
'¡ô¥O[I2]ÂX®i¦V¤UCrr°}¦CÁa¦V³Ì¤j¯Á¤Þ¦C¸¹¼Æ ªºÀx¦s®æ½d³ò,¥HCrr°}¦Cȱa¤J
Erase Brr, Brr: Set Y = Nothing
'¡ôÄÀ©ñÅܼÆ
End Sub |
|