ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] 2­Ó±ø¥óªº¥[Á`

¦^´_  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

TOP

¥»©«³Ì«á¥Ñ 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

TOP

¦pªþ¥ó¡G
¨â­Ó±ø¥óªº¥[Á`.rar (20.85 KB)

TOP

¦^´_  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

TOP

¦^´_ 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

TOP

¦^´_ 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

TOP

        ÀR«ä¦Û¦b : ¡i®É¤é²öªÅ¹L¡j¤@­Ó¤H¦b¥@¶¡°µ¤F¦h¤Ö¨Æ¡A´Nµ¥©ó¹Ø©R¦³¦hªø¡C¦]¦¹¥²¶·»P®É¶¡Ävª§¡A¤Á²ö¨Ï®É¤éªÅ¹L¡C
ªð¦^¦Cªí ¤W¤@¥DÃD