- ©«¤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
|
¦^´_ 2# Andy2483
½Æ²ß¤F¤@¤U,¤ß±oµù¸Ñ,½Ð«e½úÌ«ü¾É
Option Explicit
Sub ²Å¦X¦h±ø¥ó±a¥X¬ÛÃö¸ê°T_20221221_1()
Dim Arr(4), Brr, Crr, Da, Y, T, We
Dim Sh As Worksheet, i&, N&, j%
'¡ô«Å§iÅܼÆ:Arr¬O¤@ºû°}¦C,±qArr(0)~Arr(4),(Brr,Crr,Da,Y,T,We)¬O³q¥Î«¬ÅܼÆ,
'Sh¬O¤u§@ªíÅܼÆ,(i, N)¬Oªø¾ã¼Æ,j¬Oµu¾ã¼Æ
Set Y = CreateObject("Scripting.Dictionary")
'¡ô¥OY¬O ¦r¨å
Set Sh = ActiveSheet
'¡ô¥OSh¤u§@ªíÅܼƬO ²{¥Î¤u§@ªí(²{ªí)
Brr = Range(Sh.[A1], Sh.UsedRange)
'¡ô¥OBrr¬O ¤Gºû°}¦C!¥H²{ªí[A1]¨ì ²{ªí¸Ì¦³¨Ï¥Î®æ,³o½d³òÀx¦s®æÈˤJ
Da = InputBox("½Ð¿é¤J ¤é´Á!", "²Å¦X¦h±ø¥ó±a¥X¬ÛÃö¸ê°T", Date)
'¡ô¥ODa³o³q¥Î«¬ÅܼƬOInputBox()¨ç¦¡¦^¶ÇÈ
If Not IsDate(Da) Then Exit Sub
'¡ô¦pªG¥HIsDate()¨ç¦¡§PÂ_DaÅܼƤ£¬O¤é´Á!µ²§ôµ{§Ç°õ¦æ
We = Right(Format(Da, "aaaa"), 1)
'¡ô¥OWe³o³q¥Î«¬ÅܼƬO DaÅܼƥÎFormat()Âà¤Æ¬°¤å¦r(¬P´Á?),¦A¥ÎRight()¨ú¥X³Ì¥kÃ䪺¦r
T = Array(5, 1, 2, 3, 4)
'¡ô¥OT³o³q¥Î«¬ÅܼƬO¤@ºû°}¦C,ˤJ5ӼƦr
For i = 2 To UBound(Brr)
'¡ô³]¶¶°j°é!i±q2¨ì Brr°}¦CÁa¦V³Ì¤j¯Á¤Þ¦C¸¹¼Æ
If Trim(Brr(i, 3)) = "" Then Exit For
'¡ô¦pªGi°j°é²Ä3ÄæBrr°}¦Cȸg¹L¥hÀY§ÀªÅ¥Õ¦r¤¸«á¬O ªÅ¦r¤¸!´Nµ²§ôµ{§Ç°õ¦æ
If InStr(Brr(i, 3), We) Then
'¡ô¦pªGi°j°é²Ä3ÄæBrr°}¦Cȸ̦³¥]§tWe³o¦r¦êÅܼÆ??
If N = 0 Then
'¡ô¦pªGN³oªø¾ã¼ÆÅܼƬOªì©lÈ 0??
Crr = Arr
'¡ô¥OCrr¬O Arr³oӪŰ}¦C
For j = 0 To UBound(T)
'¡ô³]¶¶°j°é!¥Oj±q0¶]¨ì T°}¦Cªº³Ì«á¤@Ó¯Á¤Þ¸¹½X
Crr(j) = Brr(1, T(j))
'¡ô¥Oj°j°éCrr°}¦CȬO ²Ä1¦C²Ä(j°j°é¼Æ«ü¦VT°}¦CÈ)Ä檺Brr°}¦CÈ
Next
N = N + 1
'¡ô¥ONÅܼƲ֥[ 1
Y(N) = Crr
'¡ô¥O¥HNÅܼƬ°key,item¬OCrr°}¦C,ˤJY¦r¨å¤¤
End If
N = N + 1
'¡ô¥ONÅܼƲ֥[ 1
Crr = Arr
'¡ô¥OCrr¬O Arr³oӪŰ}¦C
For j = 0 To UBound(T)
'¡ô³]¶¶°j°é!¥Oj±q0¶]¨ì T°}¦Cªº³Ì«á¤@Ó¯Á¤Þ¸¹½X
Crr(j) = Brr(i, T(j))
'¡ô¥Oj°j°éCrr°}¦CȬO ²Äi°j°é¦C²Ä(j°j°é¼Æ«ü¦VT°}¦CÈ)Ä檺Brr°}¦CÈ
Next
Y(N) = Crr
'¡ô¥O¥HNÅܼƬ°key,item¬OCrr°}¦C,ˤJY¦r¨å¤¤
End If
Next
If N = 0 Then Exit Sub
'¡ô¦pªGNÅܼƬO 0,´Nµ²§ôµ{§Ç°õ¦æ
Workbooks.Add
'¡ô¥Oµ{§Ç²£¥Í¤@Ó·s¬¡¶Ã¯
[A2].Resize(N, UBound(Arr) + 1) = Application.Transpose(Application.Transpose(Y.ITEMS))
'¡ô¥O³o·s¬¡¶Ã¯±q[A2]ÂX®iÁa¦VNÅܼƦC,¾î¦VArr°}¦C¾î¦V³Ì¤j¯Á¤ÞÄ渹¼Æ+1Äæ,³o½d³òÀx¦s®æªºÈ,
'¥HY¦r¨åªºitem Âà¸m¨â¦¸,ˤJ³oÂX®iªº½d³òÀx¦s®æ¤¤
Range([A1], ActiveSheet.UsedRange).Borders.LineStyle = 1
'¡ô¥O¦³¨Ï¥ÎªºÀx¦s®æ®æ½u¬O ²Ó¹ê½u
Cells.Columns.AutoFit
'¡ô¥O©Ò¦³Àx¦s®æÄæ¼e¦Û°Ê½Õ¾ã
[2:2].Font.Bold = True
'¡ô¥O²Ä2¦Cªº¦rÅé¬O²ÊÅé
[A1].NumberFormatLocal = "m""¤ë""d""¤é"";@"
'¡ô¥O[A1]ªº®æ¦¡¬O?¤ë?¤é
[A1] = Da: [B1] = We
'¡ô¥O[A1]ȬO DaÅÜ:[B1]ȬO WeÅܼÆ
Set Y = Nothing
Set Brr = Nothing
Erase Crr, Arr
'¡ôÄÀ©ñÅܼÆ
End Sub
¯¬¦U¦ì«e½ú ¨Î¸`§Ö¼Ö |
|