- ©«¤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 ©ó 2023-1-3 15:15 ½s¿è
¦^´_ 1# sillykin
ÁÂÁ«e½úµoªí¦¹¥DÃD»P½d¨Ò
«á¾ÇÂǦ¹¥DÃD¾Ç²ß¦r¨å»P°}¦C±o¨ì¦hºØª¾ÃÑ»P¸gÅç,¥H¤U¬O«á¾Ç½m²ßVBA¤è¦¡ªº¤è®×,½Ð«e½ú°Ñ¦Ò
½Ð«e½úÌ«ü¾É,ÁÂÁÂ
°õ¦æ«e:
µ²ªG»Pĵ°T1:
µ²ªG»Pĵ°T2:
Option Explicit
Sub ¨Ì¤é´Á¨Ó¤À§O²Îp¤½¥q¤H¼Æ_20230103_1()
Dim R&, i&, j&, N&, Q&, T1$, T2$, T4$, Qv$, Y, Brr, Crr, C, Sh1, Sh2
'¡ô«Å§iÅܼÆ:(R,i,j,N,Q)¬Oªø¾ã¼ÆÅܼÆ,(T1,T2,T4,Qv)¬O¦r¦êÅܼÆ,¨ä¥¦¬O³q¥Î«¬ÅܼÆ
Set Y = CreateObject("Scripting.Dictionary")
'¡ô¥OY¬O ¦r¨å
Set Sh1 = Sheets("¸ê®Æ®w")
'¡ô¥OSh1¬O "¸ê®Æ®w"¤u§@ªí
Set Sh2 = Sheets("Á`ªí³æ")
'¡ô¥OSh2¬O "Á`ªí³æ"¤u§@ªí
Brr = Sh1.Range("A3:N" & Split(Sh1.UsedRange.Address, "$")(4))
'¡ô¥OBrr¬O¤Gºû°}¦C!ˤJ[A3]¨ìNÄæ³Ì«á¦CÀx¦s®æ
R = Sh2.Cells(Rows.Count, "A").End(3).Row
'¡ô¥OR³o¾ã¼ÆÅܼƬO "Á`ªí³æ"¤u§@ªíAÄæ³Ì«á¦³¤º®eÀx¦s®æ¦C¸¹
C = Sh2.Cells(1, Columns.Count).End(1).Column
'¡ô¥OC³o¾ã¼ÆÅܼƬO "Á`ªí³æ"¤u§@ªí²Ä1¦C³Ì¥k°¼¦³¤º®eÀx¦s®æÄ渹
Range(Sh2.Cells(R, 1), Sh2.Cells(1, C)).Offset(1, 1).ClearContents
'¡ô¥O"Á`ªí³æ"¤u§@ªí[A1]¨ìR¦CCÄæÀx¦s®æ½d³ò°¾²¾©¹¤U1¦C,°¾²¾©¹¥k1ÄæÀx¦s®æȲM°£
Crr = Range(Sh2.Cells(R, 1), Sh2.Cells(1, C))
'¡ô¥OCrr¬O¤Gºû°}¦C!ˤJ"Á`ªí³æ"¤u§@ªí[A1]¨ìR¦CCÄæÀx¦s®æÈ
For i = 2 To UBound(Crr, 2)
'¡ô³]¶¶°j°é!i±q2¨ìCrr°}¦C¾î¦V³Ì¤j¯Á¤ÞÄ渹¼Æ
Y(Crr(1, i) & "|C") = i
'¡ô¥O1¦Ci°j°éÄæCrr°}¦Cȳs±µ"|C"·íkey,item¬Oi°j°é¼Æ,©ñ¤JY¦r¨å¸Ì
Next
For i = 2 To UBound(Crr)
'¡ô³]¶¶°j°é!i±q2¨ìCrr°}¦CÁa¦V³Ì¤j¯Á¤Þ¦C¸¹¼Æ
Y(Crr(i, 1) & "|R") = i
'¡ô¥Oi°j°é¦C1ÄæCrr°}¦Cȳs±µ"|R"·íkey,item¬Oi°j°é¼Æ,©ñ¤JY¦r¨å¸Ì
Next
For Each C In [{2,10}]
'¡ô³]¶¶°j°é!¥OC¬O¤@ºû°}¦C¸Ìªº¤@û
For R = 1 To UBound(Brr)
'¡ô³]¶¶°j°é!¥OR±q1¨ìBrr°}¦CÁa¦V³Ì¤j¯Á¤Þ¦C¸¹¼Æ
T1 = Trim(Brr(R, C))
'¡ô¥OT1¬O R°j°é¦CC°j°éÄæBrr°}¦CÈ¥h°£¦r¦êÀY§ÀªºªÅ¥Õ¦r¤¸
T2 = Trim(Brr(R, C + 2))
'¡ô¥OT2¬O R°j°é¦CC+2°j°éÄæBrr°}¦CÈ¥h°£¦r¦êÀY§ÀªºªÅ¥Õ¦r¤¸
T4 = Trim(Brr(R, C + 4))
'¡ô¥OT4¬O R°j°é¦CC+4°j°éÄæBrr°}¦CÈ¥h°£¦r¦êÀY§ÀªºªÅ¥Õ¦r¤¸
If T1 = "" Or T4 = "" Then GoTo PS
'¡ô¦pªGT1¦r¦êÅܼƬOªÅ¦r¤¸©Î ¦pªGT4¦r¦êÅܼƬOªÅ¦r¤¸,´N¸õ¨ìPS:¦ì¸mÄ~Äò°õ¦æ
If Y(T1 & "|C") <> "" And Y(T4 & "|R") <> "" Then
'¡ô¦pªG¥ÎT1ÅܼƳs±µ"|C"¬dY¦r¨å¤£¬OªÅ¦r¤¸ ¦Ó¥B ¥ÎT4ÅܼƳs±µ"|R"¬dY¦r¨å¤£¬OªÅ¦r¤¸??
If T2 <> "" Then
'¡ô¦pªGT2ÅܼƤ£¬OªÅ¦r¤¸?
i = Y(Trim(Brr(R, C + 4)) & "|R"): j = Y(Trim(Brr(R, C)) & "|C")
'¡ô¥Oi¬O ¥Ó½Ð¤é¥h°£ÀY§ÀªÅ¥Õ¦r¤¸«á³s±µ"|R"¬dY¦r¨å±o¨ìªºitemÈ
'¡ô¥Oj¬O ³æ¦ì/¤ÀªÀ¥h°£ÀY§ÀªÅ¥Õ¦r¤¸«á³s±µ"|C"¬dY¦r¨å±o¨ìªºitemÈ
Crr(i, j) = Crr(i, j) + 1
'¡ô¥Oi¦CjÄæCrr°}¦CÈ +1
Else
N = N + 1
'¡ô§_«h¥ON¾ã¼ÆÅܼÆ+1
End If
ElseIf Y(T1 & "|C") = "" And Y(T4 & "|R") <> "" Then
'¡ô§_«h¦pªGT1¦r¦êÅܼƳs±µ"|C"¬dY¦r¨å¦aitemȬOªÅ¦r¤¸,
'¦Ó¥BT4¦r¦êÅܼƳs±µ"|R"¬dY¦r¨å¤£¬OªÅ¦r¤¸
Q = Q + 1
'¡ô¥OQ¾ã¼ÆÅܼÆ+1
Qv = Qv & "," & T1
'¡ô¥OQv³o¦r¦êÅܼƬO ¦Û¨È³s±µ",",¦A³s±µT1¦r¦êÅܼÆ
End If
PS:
Next
Next
Sh2.[A1].Resize(UBound(Crr), UBound(Crr, 2)) = Crr
'¡ô¥O"Á`ªí³æ"¤u§@ªí¦V¤UÂX®iCrr°}¦CÁa¦V³Ì¤j¯Á¤Þ¦C¸¹¼Æ,
'¦V¥kCrr°}¦C¾î¦V³Ì¤j¯Á¤ÞÄ渹¼Æ,³o½d³òÀx¦s®æÈ¥HCrr°}¦Cȱa¤J
Application.Goto Sh2.[A1]
'¡ô¥OÀx¦s®æ´å¼Ð¸õ¨ì "Á`ªí³æ"¤u§@ªí[A1]
If N > 0 Then MsgBox "¦@¦³ " & N & "µ§¸ê®Æ¨S¦³©m¦W,¥¼¦C¤J²Îp"
If Q > 0 Then MsgBox "¦@¦³ " & Q & "³æ¦ì/¤ÀªÀ¦b Á`ªí³æ§ä¤£¨ì" & Qv
Set Y = Nothing
Set Brr = Nothing
Set Crr = Nothing
'¡ôÄÀ©ñÅܼÆ
End Sub |
|