- ©«¤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-3 09:16 ½s¿è
ÁÂÁ½׾Â,ÁÂÁ¦U¦ì«e½ú
«á¾Ç½Æ²ß¬Q¤Ñªº²ßÃD,½Æ²ß¤ß±o¦p¤U,½Ð«ü±Ð
Option Explicit
Private Sub CommandButton5_Click()
Dim R&, R1&, i&, j%, Arr, Sh1 As Range, Sh2 As Range
'¡ô«Å§iÅܼÆ:(R,R1,i)¬Oªø¾ã¼ÆÅܼÆ,j¬Oµu¾ã¼ÆÅܼÆ,(Sh1,Sh2)¬OÀx¦s®æÅܼÆ
Set Sh1 = Sheets("¥D³õ").Cells
'¡ô¥OSh1³oÀx¦s®æÅܼƬO ¥D³õªíªº©Ò¦³Àx¦s®æ
Set Sh2 = Sheets("¼ËªO").Cells
'¡ô¥OSh2³oÀx¦s®æÅܼƬO ¼ËªOªíªº©Ò¦³Àx¦s®æ
R = Sh1(65536, 8).End(3).Row
'¡ô¥OR³oªø¾ã¼ÆÅܼƬO Sh1ÅܼƪºHÄæ³Ì«á¤@Ó¦³¤º®eªºÀx¦s®æ¦C¸¹
R1 = Sh2(65536, 8).End(3).Row
'¡ô¥OR1³oªø¾ã¼ÆÅܼƬO Sh2ÅܼƪºHÄæ³Ì«á¤@Ó¦³¤º®eªºÀx¦s®æ¦C¸¹
For i = 2 To R1
'¡ô³]¶¶°j°é!i±q2 ¨ìR1ÅܼÆ
If Sh2(i, 8) <> "" Then
'¡ô¦pªGSh2Åܼƪºi°j°é¦C²Ä8Ä椣¬OªÅ®æ(¦pªG¼ËªOªíªºHÄæiÅܼƦCÀx¦s®æ¤£¬OªÅ¥Õ)
R = R + 1
'¡ô¥ORÅܼƲ֥[1
For j = 1 To 8
'¡ô³]¶¶°j°é!j±q1¨ì 8
Sh1(R, j) = Sh2(i, j)
'¡ô¥OSh1ÅܼƪºRÅܼƦC²ÄjÅܼÆÄæÀx¦s®æȬO Sh2ÅܼƪºiÅܼƦC²ÄjÅܼÆÄæÀx¦s®æÈ
Next
End If
Next
End Sub
====================================================
Option Explicit
Private Sub CommandButton5_Click()
Dim R&, i&, j%, Arr
'¡ô«Å§iÅܼÆ:(R,i)¬Oªø¾ã¼ÆÅܼÆ,j¬Oµu¾ã¼ÆÅܼÆ,Arr¬O³q¥Î«¬ÅܼÆ
Arr = Range([¼ËªO!A1], [¼ËªO!H65536].End(3))
'¡ô¥OArr³o³q¥Î«¬ÅܼƬO ¼ËªOªí[A1]¨ìHÄæ³Ì«á¤@¦³¤º®eÀx¦s®æ,
'³o¨âÓÀx¦s®æÂX®i¥X³Ì¤pªº¤è¥¿½d³ò Àx¦s®æÈ
For i = 2 To UBound(Arr)
'¡ô³]¶¶°j°é!i±q2 ¨ìArr°}¦CÁa¦V³Ì¤j¯Á¤Þ¦C¸¹
If Arr(i, 8) <> "" Then
'¡ô¦pªGi°j°é¦C²Ä8ÄæArr°}¦CÈ ¤£¬OªÅ¦r¤¸?
R = R + 1
'¡ô¥OR³oªø¾ã¼ÆÅܼƲ֥[1
For j = 1 To UBound(Arr, 2)
'¡ô³]¶¶°j°é!j±q1 ¨ìArr°}¦C¾î¦V³Ì¤j¯Á¤ÞÄ渹
Arr(R, j) = Arr(i, j)
'¡ô¥ORÅܼƦC²ÄjÄ檺Arr°}¦CȬO i°j°é¦C²ÄjÄ檺Arr°}¦CÈ
Next
End If
Next
[¥D³õ!H65536].End(3).Item(2, -6).Resize(R, UBound(Arr, 2)) = Arr
'¡ô¥O¥D³õªíHÄæ³Ì«á¤@¦³¤º®eÀx¦s®æºâ°_,©¹¤U1¦C,©¹¥ª7Ä檺¨º¤@®æ¶}©lÂX®i,
'ÂX®i¦V¤UR¦C,¦V¥kÂX®iArr°}¦C¾î¦V³Ì¤j¯Á¤ÞÄ渹¼ÆÄæ,
'³oÂX®i½d³òÀx¦s®æÈ¥HArr°}¦Cȱa¤J
Set Arr = Nothing
'¡ôÄÀ©ñÅܼÆ
End Sub
====================================================
Option Explicit
Private Sub CommandButton5_Click()
Dim R&, i&, j%, Arr, Y, A(1 To 8)
'¡ô«Å§iÅܼÆ:(R,i)¬Oªø¾ã¼ÆÅܼÆ,j¬Oµu¾ã¼ÆÅܼÆ,(Arr,Y)¬O³q¥Î«¬ÅܼÆ
'A¬O¤@ºû°}¦C(±q1¨ì8¯Á¤Þ¸¹)
Set Y = CreateObject("Scripting.Dictionary")
'¡ô¥OY³o³q¥Î«¬ÅܼƬO ¦r¨å
Arr = Range([¼ËªO!A1], [¼ËªO!H65536].End(3))
'¡ô¥OArr³o³q¥Î«¬ÅܼƬO¤Gºû°}¦C,¥H¼ËªOªí[A1]¨ìHÄæ³Ì«á¤@¦³¤º®eÀx¦s®æ,
'³o½d³òÀx¦s®æÈˤJArr°}¦C¸Ì
For i = 2 To UBound(Arr)
'¡ô³]¶¶°j°é!i±q2 ¨ìArr°}¦CÁa¦V³Ì¤j¯Á¤Þ¦C¸¹
If Arr(i, 8) = "" Then GoTo REAR
'¡ô¦pªGi°j°é¦C²Ä8ÄæArr°}¦CȬO ªÅ¦r¤¸!
'´N¸õ¨ì REAR¼Ð¥Üªºµ{§Ç¦ì¸mÄ~Äò°õ¦æ
For j = 1 To UBound(Arr, 2)
'¡ô³]¶¶°j°é!j±q1 ¨ìArr°}¦C¾î¦V³Ì¤j¯Á¤ÞÄ渹¼Æ
A(j) = Arr(i, j)
'¡ô¥Oj¯Á¤Þ¸¹A°}¦CȬO i°j°é¦Cj°j°éÄæArr°}¦CÈ
Next
Y(Arr(i, 8)) = A
REAR: Next
[¥D³õ!H65536].End(3).Item(2, -6).Resize(Y.Count, UBound(A)) = _
Application.Transpose(Application.Transpose(Y.ITEMS))
'¡ô¥O¥D³õªíHÄæ³Ì«á¤@¦³¤º®eÀx¦s®æºâ°_,©¹¤U1¦C,©¹¥ª7Ä檺¨º¤@®æ¶}©lÂX®i,
'ÂX®i¦V¤UY¦r¨å¸ÌKey¼Æ¶q ¦C,¦V¥kÂX®iA°}¦C³Ì¤j¯Á¤Þ¸¹¼ÆÄæ,
'³oÂX®i½d³òÀx¦s®æÈ¥HY¦r¨åªºItemÂà¸m¨â¦¸«á±a¤J
Set Arr = Nothing: Set Y = Nothing: Erase A
'¡ô¥OÄÀ©ñÅܼÆ
End Sub
====================================================
Option Explicit
Private Sub CommandButton5_Click()
Dim R&, i&, j%, Arr, Y, A(1 To 8)
'¡ô«Å§iÅܼÆ:(R,i)¬Oªø¾ã¼ÆÅܼÆ,j¬Oµu¾ã¼ÆÅܼÆ,(Arr,Y)¬O³q¥Î«¬ÅܼÆ
'A¬O¤@ºû°}¦C(±q1¨ì8¯Á¤Þ¸¹)
Set Y = CreateObject("Scripting.Dictionary")
'¡ô¥OY³o³q¥Î«¬ÅܼƬO ¦r¨å
Arr = Range([¼ËªO!A1], [¼ËªO!H65536].End(3))
'¡ô¥OArr³o³q¥Î«¬ÅܼƬO¤Gºû°}¦C,¥H¼ËªOªí[A1]¨ìHÄæ³Ì«á¤@¦³¤º®eÀx¦s®æ,
'³o½d³òÀx¦s®æÈˤJArr°}¦C¸Ì
For i = 2 To UBound(Arr)
'¡ô³]¶¶°j°é!i±q2 ¨ìArr°}¦CÁa¦V³Ì¤j¯Á¤Þ¦C¸¹
If Arr(i, 8) = "" Or Y.Exists(Arr(i, 8)) <> Empty Then GoTo REAR
'¡ô¦pªGi°j°é¦C²Ä8ÄæArr°}¦CȬO ªÅ¦r¤¸!
'©Î¥Hi°j°é¦C²Ä8ÄæArr°}¦CȬ°key¬dY¦r¨å,¬d±o¨ì³okey¤w¸g¦s¦b!
'´N¸õ¨ì REAR¼Ð¥Üªºµ{§Ç¦ì¸mÄ~Äò°õ¦æ
For j = 1 To UBound(Arr, 2)
'¡ô³]¶¶°j°é!j±q1 ¨ìArr°}¦C¾î¦V³Ì¤j¯Á¤ÞÄ渹¼Æ
A(j) = Arr(i, j)
'¡ô¥Oj¯Á¤Þ¸¹A°}¦CȬO i°j°é¦Cj°j°éÄæArr°}¦CÈ
Next
Y(Arr(i, 8)) = A
REAR: Next
[¥D³õ!H65536].End(3).Item(2, -6).Resize(Y.Count, UBound(A)) = _
Application.Transpose(Application.Transpose(Y.ITEMS))
'¡ô¥O¥D³õªíHÄæ³Ì«á¤@¦³¤º®eÀx¦s®æºâ°_,©¹¤U1¦C,©¹¥ª7Ä檺¨º¤@®æ¶}©lÂX®i,
'ÂX®i¦V¤UY¦r¨å¸ÌKey¼Æ¶q ¦C,¦V¥kÂX®iA°}¦C³Ì¤j¯Á¤Þ¸¹¼ÆÄæ,
'³oÂX®i½d³òÀx¦s®æÈ¥HY¦r¨åªºItemÂà¸m¨â¦¸«á±a¤J
Set Arr = Nothing: Set Y = Nothing: Erase A
'¡ô¥OÄÀ©ñÅܼÆ
End Sub
====================================================
Option Explicit
Private Sub CommandButton5_Click()
Dim R&, i&, j%, Arr, Brr, Y, A
'¡ô«Å§iÅܼÆ:(R,i)¬Oªø¾ã¼ÆÅܼÆ,j¬Oµu¾ã¼ÆÅܼÆ,
'(Arr,Brr,Y,A)¬O³q¥Î«¬ÅܼÆ
Set Y = CreateObject("Scripting.Dictionary")
'¡ô¥OY³o³q¥Î«¬ÅܼƬO ¦r¨å
Arr = Range([¼ËªO!A1], [¼ËªO!H65536].End(3))
'¡ô¥OArr³o³q¥Î«¬ÅܼƬO¤Gºû°}¦C,¥H¼ËªOªí[A1]¨ìHÄæ³Ì«á¤@¦³¤º®eÀx¦s®æ,
'³o½d³òÀx¦s®æÈˤJArr°}¦C¸Ì
For i = 2 To UBound(Arr)
'¡ô³]¶¶°j°é!i±q2 ¨ìArr°}¦CÁa¦V³Ì¤j¯Á¤Þ¦C¸¹
If Arr(i, 8) <> "" Then Y(Arr(i, 8)) = i
'¡ô¦pªGi°j°é¦C²Ä8ÄæArr°}¦CȤ£¬OªÅ¦r¤¸!´N¥H³o°}¦CÈ·íkey,
'Item¬OiÅܼÆ,©ñ¤JY¦r¨å¸Ì
Next
ReDim Brr(1 To Y.Count, 1 To 8)
'¡ô«Å§iBrrÅܼƬO¤Gºû°}¦C!°}¦C¤j¤p½d³ò:Áa¦V1¯Á¤Þ¸¹¦C¨ì(Y¦r¨åkey¼Æ)¯Á¤Þ¸¹¦C,
'¾î¦V±q1¯Á¤Þ¸¹Äæ¨ì8¯Á¤Þ¸¹Äæ
For Each A In Y.Items
'¡ô³]¶¶°j°é!¥OA¬OY¦r¨å¸ÌItemªº¤@û
R = R + 1
'¡ô¥OR³oªø¾ã¼ÆÅܼƲ֥[1
For j = 1 To UBound(Arr, 2)
'¡ô³]¶¶°j°é!j±q1 ¨ìArr°}¦C¾î¦V³Ì¤j¯Á¤ÞÄ渹
Brr(R, j) = Arr(A, j)
'¡ô¥ORÅܼƦCjÅܼÆÄæBrr°}¦CȬO AÅܼƦCjÄæArr°}¦CÈ
Next
Next
[¥D³õ!H65536].End(3).Item(2, -6).Resize(Y.Count, 8) = Brr
'¡ô¥O¥D³õªíHÄæ³Ì«á¤@¦³¤º®eÀx¦s®æºâ°_,©¹¤U1¦C,©¹¥ª7Ä檺¨º¤@®æ¶}©lÂX®i,
'ÂX®i¦V¤UY¦r¨å¸ÌKey¼Æ¶q ¦C,¦V¥kÂX®i8Äæ,
'³oÂX®i½d³òÀx¦s®æÈ¥HBrr°}¦Cȱa¤J
Set Arr = Nothing: Set Brr = Nothing: Set Y = Nothing
'¡ôÄÀ©ñÅܼÆ
End Sub |
|