- ©«¤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
|
¥»©«³Ì«á¥Ñ Andy2483 ©ó 2022-12-12 11:23 ½s¿è
¦^´_ 8# Andy2483
¦^´_¦Û¤vªº²Ê¤ß¤j·N
Sub TEST()
Dim Brr, C&, R&, T, V$(6), Y, N&
'¡ô«Å§iÅܼÆ(Brr,T,Y)¬O³q¥Î«¬ÅܼÆ,(C,R,N)¬Oªø¾ã¼Æ,V¬O¤@ºû°}¦CV(0)~V(6)
Set Y = CreateObject("Scripting.Dictionary")
'¡ô¥OY¬O¦r¨å
Brr = ¤u§@ªí1.UsedRange.Offset(1)
'¡ô¥OBrr¬O°}¦C!ˤJ ¤u§@ªí1¦³¨Ï¥ÎÀx¦s®æªº³Ì¤p¤è¥¿°Ï°ì©¹¤U°¾²¾ 1¦CÀx¦s®æ È
T = Split("ABC,QWE,AA,BB", ",")
'¡ô¥OT¬O¥H","²Å¸¹©î¸ÑÂù¤Þ¸¹¤ºªº¦r¦ê¤@ºû°}¦C
'¯Á¤Þ¸¹0:"ABC" ;1:"QWE" ;2:"AA" ;3:"BB"
For R = 1 To UBound(Brr)
'¡ô³]¥~¶¶°j°é!R±q1¨ìBrr°}¦CÁa¦V³Ì¤j¦C¸¹
If (Brr(R, 2) = T(0) Or Brr(R, 2) = T(1)) And (Brr(R, 3) = T(2) Or Brr(R, 3) = T(3)) Then
'¡ô¦pªG(°j°é¦C²Ä2ÄæBrr°}¦CȬO"ABC ©Î °j°é¦C²Ä2ÄæBrr°}¦CȬO"QWE"),
'¦Ó¥B(°j°é¦C²Ä3ÄæBrr°}¦CȬO"AA ©Î °j°é¦C²Ä3ÄæBrr°}¦CȬO"BB")
If Trim(Brr(R, 5)) <> "" Then
'¡ô¦A¦pªG°j°é¦C²Ä5ÄæBrr°}¦CȬOªÅ¦r¤¸
N = N + 1
'¡ôN¼Æ¦rÅܼƲ֥[ 1
For C = 1 To UBound(Brr, 2)
'¡ô³]¤º¶¶°j°é!C±q1¨ì Brr°}¦C¾î¦V³Ì¤jÄ渹
V(C - 1) = Brr(R, C)
'¡ô¥OBrr°}¦CªºR°j°é¦CC°j°éÄæȱa¤JV¤@ºû°}¦C¬Û¹ï¦ì¸m¸Ì
Next
Y(Brr(R, 1) & "|" & R) = V
'¡ô¥O¥HR°j°é¦C²Ä1ÄæBrr°}¦Cȳs±µ "|" ²Å¸¹,¦A³s±µR°j°é¼Æ ¬°key,
'item¬OV¤@ºû°}¦C
End If
End If
Next
¤u§@ªí2.UsedRange.Offset(3).Clear
'¡ô¥O ¤u§@ªí2¦³¨Ï¥ÎÀx¦s®æªº³Ì¤p¤è¥¿°Ï°ì©¹¤U°¾²¾ 3¦CÀx¦s®æ²M°£
With ¤u§@ªí2.[A4].Resize(N, UBound(V) + 1)
'¡ô¦A¦¸½Æ²ß¤~Àˬd¨ìÄæ¼ÆÀ³¸Ón¥[ 1,¦]¬°UBound(V)«üªº¤£¬O°}¦C³Ì¤j¤¸¯À¼Æ!¬O³Ì¤j¯Á¤Þ¸¹
'¥H¤U¦³Ãö©ó ¤u§@ªí2.[A4]¦V¤UÂX®iN¦C,¦V¥kÂX®iV¤@ºû°}¦C³Ì¤j¯Á¤Þ¸¹¼Æ+1 ªº½d³òÀx¦s®æ
.Value = Application.Transpose(Application.Transpose(Y.ITEMS))
'¡ôÂX®i½d³òÀx¦s®æªºÈ¥HY¦r¨åªºitemÂà¸m«áˤJ
.Sort key1:=.Item(1), Header:=xlNo
'°µ±Æ§Ç!Áa¦V,°ò·ÇÄæ¦ì¬OÂX®i°Ï°ìªº²Ä 1Äæ,¨S¦³¼ÐÃD¦C
End With
Set Brr = Nothing
Set Y = Nothing
Erase T, V
'¡ôÄÀ©ñÅܼÆ
End Sub
¸ê®Æªí:
With ¤u§@ªí2.[A4].Resize(N, UBound(V))
With ¤u§@ªí2.[A4].Resize(N, UBound(V) + 1)
|
|