Board logo

¼ÐÃD: [µo°Ý] 2­Ó±ø¥óªº¥[Á` [¥´¦L¥»­¶]

§@ªÌ: yliu    ®É¶¡: 2013-5-30 23:34     ¼ÐÃD: 2­Ó±ø¥óªº¥[Á`

½Ð°Ý¦U¦ì°ª¤â,

§Ú­n±N­ì©l¸ê®Æ¸Ì¨ÌÃþ§O»P¤é´Á³o¨â­Ó±ø¥ó±Nª÷ÃB¥[Á`¨ì"Á`ªí",¨Ò¦p:1/1~1/31, AÃþª÷ÃB¥[Á`«á©ñ¨ìB4Àx¦s®æ,2/1~2/28, AÃþª÷ÃB¥[Á`«á©ñ¨ìC4Àx¦s®æ,3/1~3/31, AÃþª÷ÃB¥[Á`«á©ñ¨ìD4Àx¦s®æ..¥H¦¹Ãþ±À
­ì¥»¨Ï¥Î¤u§@ªí¨ç¼ÆSUMPRODUCT, ¦ý¸ê®Æ¶q¦h®É,¤u§@ªírun­«·s­pºâ·|ªá«Ü¦h®É¶¡, ·Q§ï¥ÎVBA¤è¦¡.
¦ý§Ú¥u·|¥Î¤U¦C¼gªk,µo²{³o¼Ë¼gªk­n¼g«Ü¦hªºIF§PÂ_,·Q½Ð°Ý¦U¦ì°ª¤â ´£¨Ñ¸û¦nªº¼gªk.·PÁÂ!

Private Sub CommandButton2_Click()
Dim rowcnt As Integer
Dim i As Integer
Dim sum_A_1, sum_A_2, sum_A_3,sum_A_4,sum_A_5,sum_A_6,sum_A_7,sum_A_8,sum_A_9,sum_A_10,sum_A_11,sum_A_12 As Variant
sum_A_1= 0 '²Î­pAÃþ1¤ë¥÷ª÷ÃB
sum_A_2= 0 '²Î­pAÃþ2¤ë¥÷ª÷ÃB
sum_A_3= 0 '²Î­pAÃþ3¤ë¥÷ª÷ÃB
sum_A_4= 0 '²Î­pAÃþ4¤ë¥÷ª÷ÃB
sum_A_5= 0 '²Î­pAÃþ5¤ë¥÷ª÷ÃB

Sheets("­ì©l¸ê®Æ").Activate
With Sheets("­ì©l¸ê®Æ")
rowcnt= .Cells(1, 1).CurrentRegion.Rows.Count

For i = 1 To rowcnt
    '¥[Á`AÃþ¤@¤ë¥÷ª÷ÃB
    If .Cells(i,2) >= "2013/1/1"And .Cells(i, 2) <= "2013/1/31" And .Cells(i,1) = Sheets("Á`ªí").Range("A4") Then
        sum_A_1= sum_A_1 + (Cells(i, 3).Value)
        Sheets("Á`ªí").Range("B4") = sum_A_1
    End If
   '¥[Á`AÃþ¤G¤ë¥÷ª÷ÃB
     If .Cells(i,2) >= "2013/2/1"And .Cells(i, 2) <= "2013/2/28" And .Cells(i,1) = Sheets("Á`ªí").Range("A4") Then
        sum_A_2= sum_A_2+ (Cells(i, 3).Value)
        Sheets("Á`ªí").Range("C4") = sum_A_2   
     End If
Next

End With
End Sub

[attach]15113[/attach][attach]15115[/attach]
§@ªÌ: kimbal    ®É¶¡: 2013-5-31 01:38

¥»©«³Ì«á¥Ñ kimbal ©ó 2013-5-31 01:40 ½s¿è

¦^´_ 1# yliu
  1. Private Sub CommandButton2_Click()
  2. Application.ScreenUpdating = False
  3. Application.Calculation = xlCalculationManual

  4. Dim rowcnt As Long
  5. Dim i As Long

  6. Dim lngVlookupRow As Long
  7. Dim lngCurrenMonth As Long
  8. Dim lngCurrValue As Long

  9. '²M²z¼ƾÚ
  10. Sheets("Á`ªí").Activate
  11. Sheets("Á`ªí").Range("A3").CurrentRegion.Offset(1, 1).Clear


  12. Sheets("­ì©l¸ê®Æ").Activate
  13. With Sheets("­ì©l¸ê®Æ")
  14.     rowcnt = .Cells(1, 1).CurrentRegion.Rows.Count
  15.     For i = 1 To rowcnt
  16.         lngCurrenMonth = 0
  17.         If IsDate(.Cells(i, 2)) Then
  18.             lngCurrenMonth = Month(.Cells(i, 2)) '·í¦æ¤ë¥÷
  19.         End If
  20.         If lngCurrenMonth > 0 And Not (IsError(Application.Match(.Cells(i, 1), Sheets("Á`ªí").Range("A:A"), 0))) Then
  21.             lngVlookupRow = Application.Match(.Cells(i, 1), Sheets("Á`ªí").Range("A:A"), 0) '·í¦æÃþ«¬¦bÁ`ªí¦æ¼Æ
  22.             lngCurrValue = .Cells(i, 3)
  23.             With Sheets("Á`ªí").Cells(lngVlookupRow, lngCurrenMonth + 1) '©ñ¼Æ¾Ú¨ìÁ`ªí¤W
  24.                 .Value = .Value + lngCurrValue
  25.             End With
  26.         End If
  27.     Next
  28.    
  29. End With

  30. Application.Calculation = xlCalculationAutomatic
  31. Application.ScreenUpdating = True
  32. End Sub
½Æ»s¥N½X

§@ªÌ: yliu    ®É¶¡: 2013-5-31 12:30

¦^´_ 2# kimbal
ÁÂÁÂkimbal.
¦ý¥X²{°õ¦æ¶¥¬q¿ù»~¡¦13¡¦: «¬ºA¤£²Å¦X
°»¿ù¦b: With Sheets("Á`ªí").Cells(lngVlookupRow, lngCurrenMonth + 1) '©ñ¼Æ¾Ú¨ìÁ`ªí¤W
§@ªÌ: stillfish00    ®É¶¡: 2013-5-31 13:07

¦^´_ 1# yliu
¦³¦Ò¼{ª½±µ¥Î¼Ï¯Ã¤ÀªRªí¶Ü?
[attach]15118[/attach]
§@ªÌ: sunnyso    ®É¶¡: 2013-5-31 13:10

¦^´_ 1# yliu

¥i¥H¦Ò¼{¥Î SUMIFS ¨Ó¥N´À SUMPRODUCT¡A ¦]爲SUMIFS§ó¦³®Ä²v
§@ªÌ: kimbal    ®É¶¡: 2013-5-31 13:27

¦^´_ 3# yliu


    ¥i§_´£¨Ñ¤@¤UEXCEL?

¥t¥~¤]·|«Øij¥ÎPIVOTTABLE ©MSUMIFS
VBA LOOP«Ü¦h±¡ªp¤]¬O¤ñ¤½¦¡ºCªº.
§@ªÌ: c_c_lai    ®É¶¡: 2013-5-31 16:23

¦^´_  kimbal
ÁÂÁÂkimbal.
¦ý¥X²{°õ¦æ¶¥¬q¿ù»~¡¦13¡¦: «¬ºA¤£²Å¦X
°»¿ù¦b: With Sheets("Á`ªí").Cells( ...
yliu µoªí©ó 2013-5-31 12:30

¦^´_ 2# kimbal
¤£¦n·N«ä¡A§Úµy·L²K¥[¤F´X¦æ¡A§Æ±æ±zµ¥¯à¯º¯Ç¡I
  1. Private Sub Ex()
  2.     Dim rowcnt As Long, i As Long
  3.     Dim lngVlookupRow As Long, lngCurrenMonth As Long, lngCurrValue As Long

  4.     Application.ScreenUpdating = False
  5.     Application.Calculation = xlCalculationManual

  6.     '  ²M²z¼ƾÚ
  7.     Sheets("Á`ªí").Activate
  8.     Sheets("Á`ªí").Range("A3").CurrentRegion.Offset(1, 1).Clear


  9.     Sheets("­ì©l¸ê®Æ").Activate
  10.     With Sheets("­ì©l¸ê®Æ")
  11.         rowcnt = .Cells(1, 1).CurrentRegion.Rows.Count
  12.         For i = 2 To rowcnt
  13.             lngCurrenMonth = 0
  14.             If IsDate(.Cells(i, 2)) Then
  15.                 lngCurrenMonth = Month(.Cells(i, 2))                                               '  ·í¦æ¤ë¥÷
  16.             End If
  17.             
  18.             If lngCurrenMonth > 0 And Not (IsError(Application.Match(.Cells(i, 1), Sheets("Á`ªí").Range("A:A"), 0))) Then
  19.                 lngVlookupRow = Application.Match(.Cells(i, 1), Sheets("Á`ªí").Range("A:A"), 0)    '  ·í¦æÃþ«¬¦bÁ`ªí¦æ¼Æ
  20.                 lngCurrValue = .Cells(i, 3)
  21.                 With Sheets("Á`ªí")
  22.                     .Cells(lngVlookupRow, lngCurrenMonth + 1).Value = .Cells(lngVlookupRow, lngCurrenMonth + 1).Value + lngCurrValue                       '  ©ñ¼Æ¾Ú¨ìÁ`ªí¤W
  23.                     .Cells(lngVlookupRow, "N") = .Cells(lngVlookupRow, "N") + lngCurrValue
  24.                     .Cells(lngVlookupRow, Chr(79 + Int(lngCurrenMonth / 4))) = .Cells(lngVlookupRow, Chr(79 + Int(lngCurrenMonth / 4))) + lngCurrValue
  25.                 End With
  26.             End If
  27.         Next
  28.     End With
  29.    
  30.     With Sheets("Á`ªí")
  31.         rowcnt = .[A3].End(xlDown).Row
  32.         For i = 2 To 18
  33.             .Cells(rowcnt, i) = WorksheetFunction.Sum(.Range(Chr(64 + i) & 4 & ":" & Chr(64 + i) & (rowcnt - 1)))
  34.         Next i
  35.     End With
  36.    
  37.     Application.Calculation = xlCalculationAutomatic
  38.     Application.ScreenUpdating = True
  39. End Sub
½Æ»s¥N½X

§@ªÌ: c_c_lai    ®É¶¡: 2013-5-31 19:52

¥»©«³Ì«á¥Ñ c_c_lai ©ó 2013-5-31 19:55 ½s¿è

½Ð±N 4 §ï¦¨ 3.2
  1.                     .Cells(lngVlookupRow, Chr(79 + Int(lngCurrenMonth / 3.2))) = .Cells(lngVlookupRow, Chr(79 + Int(lngCurrenMonth /3.2))) + lngCurrValue
½Æ»s¥N½X

§@ªÌ: c_c_lai    ®É¶¡: 2013-5-31 21:16

¦pªþ¥ó¡G
[attach]15124[/attach]
§@ªÌ: yliu    ®É¶¡: 2013-5-31 23:53

¦^´_ 9# c_c_lai


   ÁÂÁÂ c_c_lai,
   ¥i¥H¨Ï¥Î¤F, ·PÁÂ~
  ¦A½Ð°Ý¤@¤U,   
.Cells(lngVlookupRow, Chr(79 + Int(lngCurrenMonth / 3.2))) = .Cells(lngVlookupRow, Chr(79 + Int(lngCurrenMonth / 3.2))) + lngCurrValue  '

°£¥H3.2 ªº§@¥Î¬O¤°»ò?
§@ªÌ: yliu    ®É¶¡: 2013-6-1 00:02

¦^´_ 4# stillfish00


    ÁÂÁÂstillfish00, ¦]³oÀɮפ£¥u§Ú¨Ï¥Î, ©Ò¥H§Æ±æ¯à°÷¦Û°Ê¥[Á`.¤w±o¨ì¸Ñµª¤F,·PÁÂ!
§@ªÌ: yliu    ®É¶¡: 2013-6-1 00:03

¦^´_ 5# sunnyso


    ÁÂÁÂsunnyso, ¸Õ¹L§A©Ò´£ªºSUMIFS, ¥i¥H¨Ï¥Î.·PÁÂ!
§@ªÌ: yliu    ®É¶¡: 2013-6-1 00:05

¦^´_ 6# kimbal


    c_c_lai ´£¨Ñªºµ{¦¡½X¤w¥i¥H¨Ï¥Î¤F,ÁÂÁÂ!
    ¦Ósunnyso©Ò´£ªºSUMIFS½T¹ê¤]¬O¤@­Ó¤èªk.
§@ªÌ: sunnyso    ®É¶¡: 2013-6-1 00:25

¦^´_ 13# yliu
VBA¥Îloop¨Ó°µ±ø¥ó¥[Á`ªº®Ä²v¨Ã¤£·|¤ñSUMPRODUCT°ª

§Aªº¸ê®Æ¦³¦h¤Öµ§¡H
§@ªÌ: c_c_lai    ®É¶¡: 2013-6-1 07:38

¦^´_  c_c_lai


   ÁÂÁÂ c_c_lai,
   ¥i¥H¨Ï¥Î¤F, ·PÁÂ~
  ¦A½Ð°Ý¤@¤U,   
.Cells(lngVlookupRow, ...
yliu µoªí©ó 2013-5-31 23:53

¦pªG°£¥H 4¡G
1  ( Int(0.25)=0)¡A 2 ( Int(0.5))=0 )¡A     3( Int(0.75))=0 )¡A  '   ²Ä¤@©u (À³¬° 0)
4(  Int(1))=1)¡A      5( Int(1.25))= 1)¡A    6( Int(1.5 ))=1)¡A    '   ²Ä¤G©u (À³¬° 1)
7( Int(1.75))= 1)¡A 8( Int(2))=2 )¡A         9(  Int(2.25))=2)¡A   '  ²Ä¤T©u (À³¬° 2)
10(  Int(2.5))=2)¡A 11( Int(2.75 ))=2)¡A12(  Int(3))=3)          '  ²Ä¥|©u (À³¬° 3)
°£¥H 3.2¡G
1  ( Int(0.3125)=0)¡A 2 ( Int(0.625))=0 )¡A     3( Int(0.9375))=0 )¡A '   ²Ä¤@©u
4(  Int(1.25))=1)¡A      5( Int(1.5625))= 1)¡A   6( Int(1.875 ))=1)¡A    '   ²Ä¤G©u
7( Int(2.1875))= 2)¡A 8( Int(2.5))=2 )¡A           9(  Int(2.8125))=2)¡A '  ²Ä¤T©u
10(  Int(3.125))=3)¡A 11( Int(3.4375 ))=3)¡A12(  Int(3.75))=3)       '  ²Ä¥|©u
µ²½×¡G .Cells(lngVlookupRow, Chr(79 + Int(lngCurrenMonth / 3.2))) =
              .Cells(lngVlookupRow, Chr(79 + Int(lngCurrenMonth / 3.2))) + lngCurrValue
1¤ë  ¡G.Cells(lngVlookupRow, Chr(79 + 0)) = .Cells(lngVlookupRow, Chr(79 + 0)) + lngCurrValue
             .Cells(lngVlookupRow, "O") = .Cells(lngVlookupRow, "O") + lngCurrValue    '  ²Ä¤@©u
7¤ë  ¡G.Cells(lngVlookupRow, Chr(79 + 2)) = .Cells(lngVlookupRow, Chr(79 + 2)) + lngCurrValue
             .Cells(lngVlookupRow, "Q") = .Cells(lngVlookupRow, "Q") + lngCurrValue    '  ²Ä¤T©u
11¤ë¡G.Cells(lngVlookupRow, Chr(79 + 3)) = .Cells(lngVlookupRow, Chr(79 + 3)) + lngCurrValue
             .Cells(lngVlookupRow, "R") = .Cells(lngVlookupRow, "R") + lngCurrValue     '  ²Ä¥|©u
¦¹½×±oª¾¡A¦p¥H 3.2 §@¬°¤À¥À°£¤§¡B¦A¥H Int() ¨Ó¹LÂo¡A±o­È±o¥H¥¿½TÅã¥Ü¡A¤£­PÂkÃþ¿ù»~¡C
§@ªÌ: sunnyso    ®É¶¡: 2013-6-1 08:36

¥»©«³Ì«á¥Ñ sunnyso ©ó 2013-6-1 08:40 ½s¿è

¦^´_ 15# c_c_lai

À³¸Ó§â¸ê®Æ¤@¦¸Åª¤J°}¦C, µM«á¦bVBA¤¤­pºâ¦¨°}¦C,³Ì«á§â­pºâ¦nªº°}¦C¦^¶Ç¨ì¤u§@ªí¡C
´î¤Öª«¥óŪ¼g¦¸¼ÆVBAªº®Ä²v¤~°ª

¥Ø«eµo²{VBAªº®Ä²v¤ñSUMIFS§C

¥i¥H°Ñ¦Ò³oùØ
http://forum.twbts.com/thread-9607-1-1.html
§@ªÌ: c_c_lai    ®É¶¡: 2013-6-1 11:09

¦^´_ 16# sunnyso
SUMIFS ªº³B²zªº½TÆZ²¼äªº¡A­È±o¬ã¨s¤ÎÀ³¥Î¡A
¥H©¹(¤u§@)§Ú¬O°¾­«©ó±q¨ÆÀ³¥Î³nÅé»Pºô­¶À³¥Î¤è­±¡A
±qµL¾÷½t±µÄ²¹L Excel¡A°h¤U«á¬°À°§U¤Í¤H¤~¶}©l±µÄ²
Excel (·s¤â)¡A ¬O¬G¸û¤Ö¨Ï¥Î¦¹Ãþ¦ü¤§¨ç¼Æ¡A
ÁÂÁ§Aªº«ü±Ð¡I ¥¦¹ï§ÚÆZ¦³§U¯qªº¡A¦A¦¸ÁÂÁ¡I
§@ªÌ: yliu    ®É¶¡: 2013-6-1 23:22

¦^´_ 15# c_c_lai

ÁÂÁ¸Բӻ¡©ú
§@ªÌ: yliu    ®É¶¡: 2013-6-1 23:36

¦^´_ 14# sunnyso

¥Ø«e²Ö¿n¸ê®Æ¬O700µ§¥ª¥k, ¨ì¦~©³À³¸Ó·|¦³2000µ§.
¥»¨Ó¥uª¾¹DSUMIF ¨ç¼Æ, ¦ýSUMIF¨ç¼Æ¥u­­¥Î©ó³æ¤@±ø¥ó, ÁÂÁ´£¨ÑSUMIFS.
¦ýSUMIFSÀ³¸Ó¬O2010ª©¥»¤~¦³ªº¨ç¼Æ.
§@ªÌ: yliu    ®É¶¡: 2013-6-1 23:54

¦^´_ 16# sunnyso

½Ð°Ý: µ{¦¡½X¤¤...Array("AÃþ", "BÃþ", "CÃþ", "DÃþ", "EÃþ", "FÃþ", "GÃþ", "HÃþ", "IÃþ", "JÃþ")
§Y­Y±Ä¥Î°}¦C,  ´N¬O·í¦³·sªºÃþ§O¶µ¥Ø®É, ´N»Ý­×§ïµ{¦¡½X,¨Ò¦p¡G¤é«á¥i¯à·s¼WKÃþ®É, ´N»Ý­×§ïµ{¦¡¬O¶Ü¡H
¨º±Ä¥Î°}¦C¤è¦¡´N·|¨ü­­¨î,¬O§_¦³§Oªº¤è¦¡©O¡H
§@ªÌ: sunnyso    ®É¶¡: 2013-6-2 00:12

¦^´_ 20# yliu

Ãþ§O°}¦C¥i¥H±qÁ`ªíŪ¨ú, ¤]¥i¥H±q­ì©l¸ê®ÆªíAÄæ§â¤£­«´_ªºÅª¥X¡]¨Ò¦p¦r¨åªk¡^
§@ªÌ: c_c_lai    ®É¶¡: 2013-6-2 10:45

¦^´_ 18# yliu
§Ú±N­ì¥» Kimbal ª©¤j´£¨Ñªº­×¥¿µ{¦¡¦b¤©¼W­×¡A
¥H¤Î sunnyso «e½ú´£¨Ñªºµ{¦¡²¤¤©­×¥¿«á¡A¼g¦¨¨â²Õ
®Ä¯q¤£¿ùªº¼Ò²Õ¡A¨Ñ©p¿ï¥Î¡C
A.  ¤§«e´£¨Ñªº¡A§ï¥H°}¦C³B²z (­ì¥»¬O¹ïÀ³¹êÅéÄæ¦ì¤@¤@³B²z)¡A
       ¸g­×¥¿«áªºµ{¦¡½X¡G
  1. Sub Ex_Match_Case()         '  Match Case
  2.     Dim RowsCnt As Long, i As Long, SubTotalAr() As Double
  3.     Dim t1 As Variant, t2 As Variant, AllType As Variant
  4.     Dim DataArea As Variant, Atype As Integer
  5.     Dim lngCurrenMonth As Long, lngCurrValue As Long

  6.     t1 = Timer
  7.     Application.ScreenUpdating = False
  8.     '  Application.Calculation = xlCalculationManual

  9.     AllType = Array("AÃþ", "BÃþ", "CÃþ", "DÃþ", "EÃþ", "FÃþ", "GÃþ", "HÃþ", "IÃþ", "JÃþ")
  10.     ReDim SubTotalAr(0 To UBound(AllType), 0 To 16)
  11.    '  ²M²z¼ƾÚ
  12.     Sheets("Á`ªí").Activate
  13.     Sheets("Á`ªí").Range("A3").CurrentRegion.Offset(1, 1).Clear

  14.     Sheets("­ì©l¸ê®Æ").Activate
  15.     With Sheets("­ì©l¸ê®Æ")
  16.         RowsCnt = .Cells(1, 1).CurrentRegion.Rows.Count
  17.         DataArea = .Range("A2").Resize(RowsCnt - 1, 3)
  18.         
  19.         For i = 1 To UBound(DataArea)
  20.             lngCurrenMonth = 0
  21.             If IsDate(DataArea(i, 2)) Then
  22.                 lngCurrenMonth = Month(DataArea(i, 2))                                               '  ·í¦æ¤ë¥÷
  23.             End If
  24.             
  25.             If lngCurrenMonth > 0 Then
  26.                 lngCurrValue = DataArea(i, 3)
  27.                         
  28.                 For Atype = 0 To UBound(AllType)                '  AÃþ To JÃþ
  29.                     If DataArea(i, 1) = AllType(Atype) Then     '  Jan To Dec
  30.                         SubTotalAr(Atype, lngCurrenMonth - 1) = SubTotalAr(Atype, lngCurrenMonth - 1) + lngCurrValue
  31.                         SubTotalAr(Atype, 12) = SubTotalAr(Atype, 12) + lngCurrValue     '  ²Ö­p
  32.                         SubTotalAr(Atype, 13 + Int(lngCurrenMonth / 3.2)) = SubTotalAr(Atype, 13 + Int(lngCurrenMonth / 3.2)) + lngCurrValue
  33.                         '  °£¥H 3.2¡G
  34.                         '  1 (Int(0.3125)=0)¡A  2 (Int(0.625))=0 )¡A 3 (Int(0.9375))=0 )¡A  '  ²Ä¤@©u
  35.                         '  4 (Int(1.25))=1)¡A   5 (Int(1.5625))= 1)¡A6 (Int(1.875 ))=1)¡A   '  ²Ä¤G©u
  36.                         '  7 (Int(2.1875))= 2)¡A8 (Int(2.5))=2 )¡A   9 (Int(2.8125))=2)¡A   '  ²Ä¤T©u
  37.                         '  10(Int(3.125))=3)¡A  11(Int(3.4375 ))=3)¡A12(Int(3.75))=3)       '  ²Ä¥|©u
  38.                         '  *************************************************************************************
  39.                     End If
  40.                 Next Atype
  41.             End If
  42.         Next i
  43.     End With
  44.    
  45.     With Sheets("Á`ªí")
  46.         .Range("B4").Resize(UBound(AllType) + 1, 17) = SubTotalAr
  47.         '  RowsCnt = .[A3].End(xlDown).Row
  48.         ' For i = 2 To 18
  49.         '      .Cells(RowsCnt, i) = WorksheetFunction.Sum(.Range(Chr(64 + i) & 4 & ":" & Chr(64 + i) & (RowsCnt - 1)))   '  ¦X­p
  50.         '  Next i
  51.         .Range("B14:R14").FormulaR1C1 = "=SUM(R[-10]C:R[-1]C)"
  52.     End With
  53.    
  54.     '  Application.Calculation = xlCalculationAutomatic
  55.     Application.ScreenUpdating = True
  56.     t2 = Timer
  57.     '  MsgBox "¯Ó®É" & t2 - t1
  58.     Sheets("­ì©l¸ê®Æ").[F11] = "¯Ó®É¡G " & CDbl(t2 - t1)
  59. End Sub
½Æ»s¥N½X
B.  ¸g´ú¸Õ¡A®Ä¯q³Ì¨Îªºµ{¦¡¼Ò²Õ¡G
  1. Sub Ex_VBA_Array()          '  VBA Code DataArea Array
  2.     Dim RowsCnt As Long, m As Long, SubTotalAr() As Double
  3.     Dim t1 As Variant, t2 As Variant, AllType As Variant
  4.     Dim DataArea As Variant
  5.     Dim i%, j%
  6.    
  7.     t1 = Timer
  8.     AllType = Array("AÃþ", "BÃþ", "CÃþ", "DÃþ", "EÃþ", "FÃþ", "GÃþ", "HÃþ", "IÃþ", "JÃþ")
  9.     ReDim SubTotalAr(0 To UBound(AllType), 0 To 11)
  10.     Application.ScreenUpdating = False
  11.    
  12.     '  ²M²z¼ƾÚ
  13.     '  Sheets("Á`ªí").Activate
  14.     Sheets("Á`ªí").Range("A3").CurrentRegion.Offset(1, 1).Clear
  15.    
  16.     With Sheets("­ì©l¸ê®Æ")
  17.         RowsCnt = .Range("A1").CurrentRegion.Rows.Count
  18.         DataArea = .Range("A2").Resize(RowsCnt - 1, 3)
  19.         
  20.         For m = 1 To UBound(DataArea)
  21.             For i = 0 To UBound(AllType)                '  AÃþ To JÃþ
  22.                 If DataArea(m, 1) = AllType(i) Then     '  Jan To Dec
  23.                     SubTotalAr(i, Month(DataArea(m, 2)) - 1) = SubTotalAr(i, Month(DataArea(m, 2)) - 1) + DataArea(m, 3)
  24.                 End If
  25.             Next i
  26.         Next m
  27.     End With
  28.    
  29.     With Sheets("Á`ªí")
  30.         .Range("B4").Resize(UBound(AllType) + 1, 12) = SubTotalAr
  31.         .Range("N4:N13").FormulaR1C1 = "=SUM(RC[-12]:RC[-1])"
  32.         For i = 0 To 3
  33.             '  .Range(Chr(79 + i) & 4 & ":" & Chr(79 + i) & 13).FormulaR1C1 = "=SUM(RC[-" & (13 - i * 2) & "]:RC[-" & (11 - i * 2) & "])"
  34.             .Range(Chr(79 + i) & 4).Resize(UBound(AllType) + 1).FormulaR1C1 = "=SUM(RC[-" & (13 - i * 2) & "]:RC[-" & (11 - i * 2) & "])"
  35.             .Range(Chr(79 + i) & 4).Resize(UBound(AllType) + 1) = .Range(Chr(79 + i) & 4).Resize(UBound(AllType) + 1).Value
  36.         Next i
  37.         .Range("B14:R14").FormulaR1C1 = "=SUM(R[-10]C:R[-1]C)"
  38.     End With
  39.     Application.ScreenUpdating = True
  40.     t2 = Timer
  41.     '  MsgBox "¯Ó®É" & t2 - t1
  42.     Sheets("­ì©l¸ê®Æ").[F3] = "¯Ó®É¡G " & CDbl(t2 - t1)
  43. End Sub
½Æ»s¥N½X
¥H¤W¨â²Õ¼Ò²Õ¡A§¡¨Ï¥Î 70 µ§¡B¥H¤Î 52,993 µ§¤§¸ê®Æ (sunnyso «e½ú´£¨Ñ) ´ú¸Õ¹L¡C
©p¥i¥H¦Û¦æ´ú´ú¬Ý¡C
§@ªÌ: Andy2483    ®É¶¡: 2023-4-26 16:45

ÁÂÁ½׾Â,ÁÂÁ¦U¦ì«e½ú
«á¾ÇÂǦ¹©«½m²ß°}¦C»P¦r¨å,¾Ç²ß¤è®×¦p¤U,½Ð¦U¦ì«e½ú«ü±Ð

°õ¦æ«e:
[attach]36228[/attach]

°õ¦æµ²ªG:
[attach]36229[/attach]


Option Explicit
Sub TEST()
Dim Brr, Crr, Y, i&, j&, T1$, T2$, T3%
Dim Sh1 As Worksheet, Sh2 As Worksheet
Set Y = CreateObject("Scripting.Dictionary")
Set Sh1 = Sheets("­ì©l¸ê®Æ"): Set Sh2 = Sheets("Á`ªí")
Brr = Range(Sh1.[C2], Sh1.Cells(Rows.Count, "A").End(3))
Sh2.[B4:R14].ClearContents: Crr = Sh2.[A3:R14]
For i = 1 To UBound(Brr)
   T1 = Brr(i, 1): T2 = Format(Brr(i, 2), "M¤ë"): T3 = Brr(i, 3)
   Y(T1 & "|" & T2) = Y(T1 & "|" & T2) + T3
Next
For i = 2 To UBound(Crr) - 1
   For j = 2 To 13: Crr(i, j) = 0 + Y(Crr(i, 1) & "|" & Crr(1, j)): Next
Next
With Sh2
   .[A3:R14] = Crr
   .[N4:N13] = "=SUM(B4:M4)"
   .[O4:O13] = "=SUM(B4:D4)"
   .[P4:P13] = "=SUM(E4:G4)"
   .[Q4:Q13] = "=SUM(H4:J4)"
   .[R4:R13] = "=SUM(K4:M4)"
   .[B14:R14] = "=SUM(B4:B13)"
End With
Set Y = Nothing: Set Sh1 = Nothing: Set Sh2 = Nothing: Erase Brr, Crr
End Sub




Åwªï¥úÁ{ ³Â»¶®a±Ú°Q½×ª©ª© (http://forum.twbts.com/)