Board logo

¼ÐÃD: [µo°Ý] ¦p¦ó´£°ª¦h±ø¥ó¥[Á`®Ä²v SUMIFS vs SUMPRODUCT vs VBA [¥´¦L¥»­¶]

§@ªÌ: sunnyso    ®É¶¡: 2013-6-1 04:43     ¼ÐÃD: ¦p¦ó´£°ª¦h±ø¥ó¥[Á`®Ä²v SUMIFS vs SUMPRODUCT vs VBA

¦h±ø¥ó¥[Á`®Ä²v SUMIFS³Ì§Ö¡ASUMPRODUCT ¦¸¤§
§Ú¼gªºVBA³ÌºC¡C
¤£ª¾¹D¦U¦ì¤j¤j¯à§_«üÂI¤@¤U¡A¬O§_¦³¿ìªk´£°ªVBAªº®Ä²v¡C

[attach]15127[/attach]
§@ªÌ: c_c_lai    ®É¶¡: 2013-6-1 16:35

¦^´_ 1# sunnyso
½Ð±Ð¤@­Ó°ÝÃD¡G
  1. fSumIFs = "=SUMIFS(­ì©l¸ê®Æ!R2C3:R" & RowsCnt & "C3,­ì©l¸ê®Æ!R2C1:R" & RowsCnt & "C1,Á`ªí!RC1,­ì©l¸ê®Æ!R2C5:R" & RowsCnt & "C5, COLUMN(R[-3]C[-1]))"
½Æ»s¥N½X
¨ä¤¤³Ì§ÀºÝ¤§ COLUMN(R[-3]C[-1]) «üªº¬O¡H ¥¦ªº¥Î·N¦ó¦b¡H
ÁÂÁ§A¡I
§@ªÌ: sunnyso    ®É¶¡: 2013-6-1 16:50

¦^´_ 2# c_c_lai

=column(a1)=1 to 12 (¤ë¡^
§@ªÌ: c_c_lai    ®É¶¡: 2013-6-1 18:41

¦^´_  c_c_lai

=column(a1)=1 to 12 (¤ë¡^
sunnyso µoªí©ó 2013-6-1 16:50

­ì¨Ó¦p¦¹¡A¸U¤À·P¿E¡I
§@ªÌ: c_c_lai    ®É¶¡: 2013-6-1 22:26

¦^´_ 1# sunnyso
¸Õ¸Õ³o­Óµ{¦¡½X¡A¯Ó®É 0.921875
  1. Sub Ex_VBA_Array()          '  VBA Code 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, 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 " & (t2 - t1)
  43. End Sub
½Æ»s¥N½X
[attach]15130[/attach]
§@ªÌ: Hsieh    ®É¶¡: 2013-6-1 23:22

¦^´_ 1# sunnyso
  1. Sub ex()
  2. Dim ap(11, 17), s#, i&, j%, k%, cnt#
  3. s = Timer
  4. Set dic = CreateObject("Scripting.Dictionary") '¤ë
  5. ay = Array("1¤ë", "2¤ë", "3¤ë", "4¤ë", "5¤ë", "6¤ë", "7¤ë", "8¤ë", "9¤ë", "10¤ë", "11¤ë", "12¤ë", "", "1©u", "2©u", "3©u", "4©u")
  6. ak = Array("AÃþ", "BÃþ", "CÃþ", "DÃþ", "EÃþ", "FÃþ", "GÃþ", "HÃþ", "IÃþ", "JÃþ")
  7. With Sheets("­ì©l¸ê®Æ")
  8.    ar = .Range("A1").CurrentRegion.Value
  9.    For i = 2 To UBound(ar, 1)
  10.       dic(ar(i, 1) & Month(ar(i, 2)) & "¤ë") = dic(ar(i, 1) & Month(ar(i, 2)) & "¤ë") + ar(i, 3) '¤ë
  11.       dic(ar(i, 1)) = dic(ar(i, 1)) + ar(i, 3)   '²Ö­p
  12.       dic(ar(i, 1) & Int((Month(ar(i, 2)) - 1) / 3) + 1 & "©u") = dic(ar(i, 1) & Int((Month(ar(i, 2)) - 1) / 3) + 1 & "©u") + ar(i, 3)
  13.    Next
  14. End With
  15. For j = 0 To 16
  16. cnt = 0
  17.    For k = 0 To 9
  18.       ap(k, j) = dic(ak(k) & ay(j))
  19.       cnt = cnt + dic(ak(k) & ay(j))
  20.    Next
  21.     ap(10, j) = cnt
  22. Next
  23. Sheets("Á`ªí").[B4].Resize(11, 17) = ap
  24. MsgBox Timer - s
  25. End Sub
½Æ»s¥N½X

§@ªÌ: sunnyso    ®É¶¡: 2013-6-2 00:16

¦^´_ 6# Hsieh
·PÁ¶Wª©, ¦r¨åªk§®. Åý§Ú¥Î®É¶¡¦n¦n®ø¤Æ¤@¤U. ¦³°ÝÃD¦A°Ý. Thanks in advance.

³o¸Ì¯u¬O­Óªøª¾ÃѪº¦a¤è¡C°ª¤â¦p¤ª¡C
§@ªÌ: ML089    ®É¶¡: 2013-6-2 08:42

¦^´_ 1# sunnyso

¦³·N«äªº¤ñ¸û¡A§Ú´ú¸Õµ²ªG©M§Aªº¤£¦P

1.662109375        SUMIF
9.76953125        AutoFilter
4.728515625        VBA CODE
10.07226563        SUMPRODUCT
0.654296875        ¶Wª©Hsieh
0.3359375        c_c_lai

SUMPRODUCT³ÌºC¡C¤½¦¡¸ÌCOUNTIF¤ÎSUMPRODUCT³£¬OºC­¦¤¤¨ç¼Æ

.xlsb ¶}±Ò®É¨Ã¨S¦³³qª¾¥¨¶°¦w¥þªº³qª¾¡A¶}±Ò«á¤]¥i¥H°õ¦æ¥¨¶°¡A³o¬O.xlsb ªº¯S©Ê¶Ü?
§@ªÌ: sunnyso    ®É¶¡: 2013-6-4 12:07

¦^´_ 8# ML089

¦b¥t¤@»O¹q¸£ i3-2120¡]3.3GHz¡^+4GRAM¡A µ²ªG¦p¤U
1.301        SUMIFS
3.87        AutoFilter
3.602        VBA CODE
5.023        SUMPRODUCT
0.481        ¶Wª©Hsieh-¦r¨å
10.18        c_c_lai

1.µLºÃ¶Wª©ªº³Ì§Ö
2.SUMIFS¦¸¤§
3.­«ÂI¬OVBA For Loop ©M SUMPRODUCT¡BAutoFilterªº®Ä²v¹ï¤ñ ¡]1¼Ó´ú¸Õ¦b¤@»ONetbook¤W¡^
¦n¹³For Loop ¨üCPU©MRAMªº­­¨î¸û©úÅã¡Cµy«á¦³®É¶¡¦b§âNetbookªº´ú¸Õ®É¶¡©ñ¤W¨Ó¡C
4.§AªºµwÅé°t³Æ¦p¦ó¡H¦U¦ì¦³®É®É¶¡´£¨Ñ¤@¤UµwÅé°t³Æ©M´ú¸Õ®É¶¡¡C¬Ý¬Ý¤W­±ªº²q´ú¬O§_¥¿½T¡C
5. ½Ð°Ý§A´ú¸Õc_c_laiªºcode¬O´ú¸Õ¦h¤Ö¦Cªº¸ê®Æ¡]70µ§¡AÁÙ¬O52933µ§¡^
6. xlsbªºÀÉ®×size©úÅã¤ñxlsx¡A xlsm¤p¡A³t«×²¤²¤§Ö¡C ÁÙ¬O·|¦³¦w¥þ´£¥Ü¡C§Ú¤@¯ë·|¥Îxlsb¨Ó¦sÀÉ
§@ªÌ: ML089    ®É¶¡: 2013-6-4 12:42

¦^´_ 9# sunnyso

³o¬O¿ì¤½«Ç¹q¸£ CPU: i5-760 2.8GHz / RAM 4G / WIN7-32 / EXCEL 2007
´ú¸Õ¸ê®Æ52993µ§¡A´N¬O§AªºÀɮקڦA±N¶Wª©Hsieh¤Îc_c_lai  VBAC CODE½Æ»s¶i¨Ó¤Î°õ¦æ
1.223         SUMIF
8.074         AutoFilter
4.148         VBA CODE
6.652         SUMPRODUCT
0.574         ¶Wª©Hsieh
0.418         c_c_lai

c_c_lai ªº®É¶¡¦n¹³®t²§«Ü¤j

XLSB¶}±Ò¦³VBA¦w¥þ©Ê½T»{(¤W¦¸¦b®a¸Ì´ú¸Õ¨S¦³¥X²{¡A)


³o¬O§Ú°õ¦æªºÀÉ®×
[attach]15158[/attach]
§@ªÌ: sunnyso    ®É¶¡: 2013-6-4 12:54

¦^´_ 10# ML089

¬Ý¨ÓCPUªºcache¹ïª«¥óªºÅª¨ú®Ä²v¦³«Ü¤j¼vÅT
§@ªÌ: stillfish00    ®É¶¡: 2013-6-4 20:05

¬Ý§¹1#ªþ¥ó¡A²Ä¤@¤ÏÀ³¬Oı±o²Ä¤TºØ¤èªkªºVBA CODE ¤¤ For¤Uªº¤£¤Ó¦n¡A­n¬°¥L¥­¤Ï !!! À³¸Ó¬O¹³c_c_lai¤j³o¼Ë¤~¹ï~~~¡C
¥t¥~5# c_c_laiªºcode¡A­n¦A°l¨D®Ä²vªº¸Ü¡A¥i¥H¦b23¦æ«á¥[­ÓExit For  ¡AÀ³¸Ó¯à¦A´£¤É¤@¨Ç®Ä²v¡C
©ÎªÌ¥ÎÅܼƦs©ñMonth(...)­pºâ¥X¨Óªº­È(³o­Ó¼vÅT¤ñ¸û¤p..)¡C
§@ªÌ: sunnyso    ®É¶¡: 2013-6-5 00:23

¦^´_ 12# stillfish00

Stillfish00¤j¤jªº½T¼F®`¡A¨º­ÓcodeªGµM¦³°ÝÃD¡A§ï¤F¤@¤U¡]§Ö¤F«Ü¦h¡^¡A½Ð«ü±Ð
  1. Sub sonny3_v2()
  2.     t1 = Timer
  3.     Dim RowsCnt, m, SubTotalAr() As Double
  4.     Dim DataArea As Variant
  5.     Dim i%, j%
  6.     AllType = Array("AÃþ", "BÃþ", "CÃþ", "DÃþ", "EÃþ", "FÃþ", "GÃþ", "HÃþ", "IÃþ", "JÃþ")
  7.     ReDim SubTotalAr(0 To UBound(AllType), 0 To 11)
  8.     Application.ScreenUpdating = False
  9.     With Sheets("­ì©l¸ê®Æ")
  10.         RowsCnt = .Range("A1").CurrentRegion.Rows.Count
  11.         DataArea = .Range("A2").Resize(RowsCnt - 1, 3)
  12.         For m = 1 To UBound(DataArea)
  13.             i = -1
  14.             Do
  15.                 i = i + 1
  16.             Loop Until DataArea(m, 1) = AllType(i)
  17.             j = -1
  18.             Do
  19.                 j = j + 1
  20.             Loop Until Month(DataArea(m, 2)) = (j + 1)
  21.             SubTotalAr(i, j) = SubTotalAr(i, j) + DataArea(m, 3)
  22.         Next m
  23.     End With
  24.    
  25.     With Sheets("Á`ªí")
  26.         .Range("B4").Resize(UBound(AllType) + 1, 12) = SubTotalAr
  27.         .Range("B14:R14").FormulaR1C1 = "=SUM(R[-10]C:R[-1]C)"
  28.         .Range("N4:N13").FormulaR1C1 = "=SUM(RC[-12]:RC[-1])"
  29.         .Range("O4:R13").FormulaR1C1 = "=SUM(RC[-13]:RC[-11])"
  30.     End With
  31.     Application.ScreenUpdating = True
  32.     t2 = Timer
  33.     MsgBox "¯Ó®É" & t2 - t1
  34. End Sub
½Æ»s¥N½X

§@ªÌ: ML089    ®É¶¡: 2013-6-5 21:15

¦^´_ 13# sunnyso


    ¤£¥u§Ö«Ü¦h¡A0.312¬í¡A¬O³Ì§Öªº
§@ªÌ: ML089    ®É¶¡: 2013-6-5 21:38

¦^´_ 13# sunnyso
  1. j = -1
  2. Do
  3. j = j + 1
  4. Loop Until Month(DataArea(m, 2)) = (j + 1)
  5. §ï¬°¤U¦¡
  6. j = Month(DataArea(m, 2)) - 1
  7. ·|§ó§Ö
½Æ»s¥N½X

§@ªÌ: sunnyso    ®É¶¡: 2013-6-6 08:40

¦^´_ 15# ML089

ªº½T·|§ó§Ö

¦ý¬O¥u¯à¥Î¦b³oºØ¯S®í±¡ªp, ¨Ò¦p±ø¥ó¤G¬°¦a°Ï¡]¤¤³¡,ªF¥_³¡,«n³¡...¡^´N¤£¾A¥Î

p.s. ³oùØ·Q°Q½×¤ñ¸û³q¥Îªº±ø¥ó¥[Á`¥[³tªk
³oùتº¸ê®Æ¬O°Ñ·Ó½×¾ÂùØ¥t¤@­Ó¶K½s¥X¨Óªº, ·íªì¨S¦³¦Ò¼{¨ì¥¦ªº¯S®í©Ê¡C
§@ªÌ: sunnyso    ®É¶¡: 2013-6-6 09:09

¦^´_  sunnyso
ML089 µoªí©ó 2013-6-5 21:38


·íµM³]­pµ{§Ç®É¥R¤À§Q¥Î°ÝÃDªº¯S©Êµ´¹ï¬O¥¿½Tªº¡C
§@ªÌ: ML089    ®É¶¡: 2013-6-6 09:29

¦^´_ 16# sunnyso

A CODE ­×§ï¬° B CODE¡A°õ¦æ®É¶¡¥Ñ 0.257¬íÅܺC¬°1.304¬í¡AÅܱo«ÜºC
¦bVBA¤º¥Î¬¡­¶Ã¯¨ç¼Æ·|¼W¥[«Ü¦h®É¶¡
¤£ª¾VBA¤º¦³µL¨ä¥L¥i¨ú¥NMATCH¨ç¼Æ

' *** A CODE ***
i = -1
Do
i = i + 1
Loop Until DataArea(m, 1) = AllType(i)

' *** B CODE ***
i = Application.Match(DataArea(m, 1), AllType, 0) - 1
§@ªÌ: sunnyso    ®É¶¡: 2013-6-6 09:52

¦^´_ 18# ML089
Netbook  N470 (1.83GHz) + 2GRAM ´ú¸Õµ²ªG

4.234375        SUMIFS
21.234375        AutoFilter
26.953125        VBA Code
18.203125        SUMPRODUCT
1.078125        ¶Wª©Hsieh
1.390625        New VBA Code
§@ªÌ: sunnyso    ®É¶¡: 2013-6-6 11:51

¦^´_ 15# ML089

µ²¦XML089ªº¤èªk¡A§Q¥Î­ì©l¸ê®Æªº¯S©Ê¤U­±ªºCODE§ó§Ö
  1. Sub sonny3_v3()
  2.     t1 = Timer
  3.     Dim RowsCnt, m, SubTotalAr() As Double
  4.     Dim DataArea As Variant
  5.     Dim i%, j%
  6.     AllTypeStr = "AÃþBÃþCÃþDÃþEÃþFÃþGÃþHÃþIÃþJÃþ"
  7.     ReDim SubTotalAr(0 To UBound(AllType), 0 To 11)
  8.     Application.ScreenUpdating = False
  9.     With Sheets("­ì©l¸ê®Æ")
  10.         RowsCnt = .Range("A1").CurrentRegion.Rows.Count
  11.         DataArea = .Range("A2").Resize(RowsCnt - 1, 3)
  12.         For m = 1 To UBound(DataArea)
  13.             i = (InStr(AllTypeStr, "DÃþ") + 1) / 2
  14.             j = Month(DataArea(m, 2)) - 1
  15.             SubTotalAr(i, j) = SubTotalAr(i, j) + DataArea(m, 3)
  16.         Next m
  17.     End With
  18.    
  19.     With Sheets("Á`ªí")
  20.         .Range("B4").Resize(UBound(AllType) + 1, 12) = SubTotalAr
  21.         .Range("B14:R14").FormulaR1C1 = "=SUM(R[-10]C:R[-1]C)"
  22.         .Range("N4:N13").FormulaR1C1 = "=SUM(RC[-12]:RC[-1])"
  23.         .Range("O4:R13").FormulaR1C1 = "=SUM(RC[-13]:RC[-11])"
  24.     End With
  25.     Application.ScreenUpdating = True
  26.     t2 = Timer
  27.     MsgBox "¯Ó®É" & t2 - t1
  28. End Sub
½Æ»s¥N½X

§@ªÌ: sunnyso    ®É¶¡: 2013-6-6 11:54

¥»©«³Ì«á¥Ñ sunnyso ©ó 2013-6-6 11:56 ½s¿è

¦^´_ 18# ML089

¦³¤@­Ó·Qªk¡A §Q¥ÎVBA ªº InStr()¡Afilter, join µ¥ ¨ç¼Æ¡C¦ý¬OÁÙ¨S·Q¨ì¨ãÅé¦p¦ó¹ê²{
§@ªÌ: sunnyso    ®É¶¡: 2013-6-6 13:23

¦^´_ 18# ML089

¤@¯ë¨Ó»¡­n´£°ª¥¨¶°®Ä²vÀ³¸Ó´î¤Ö¨Ï¥Î¬¡­¶Ã¯¨ç¼Æ©M¹ï¬¡­¶Ã¯ª«¥óªºÅª¼g

Sub test1()
    Dim i%, j%
    Dim Ar(1000, 1000) As Double
    For i = 0 To 1000
        For j = 0 To 1000
            Ar(i, j) = i * 4 + j
        Next j
    Next i
    Range(Cells(1, 1), Cells(1001, 1001)) = Ar
End Sub

Sub test2()
    Dim i%, j%
    For i = 1 To 1000
        For j = 1 To 1000
           Cells(i, j) = i * 4 + j
        Next j
    Next i
End Sub
§@ªÌ: sunnyso    ®É¶¡: 2013-6-6 15:06

§â¸ê®Æ±q¤u§@ªíŪ¤J°}¦C, ¦A§@¹Bºâ, ¹Bºâ¦¨°}¦C,¦A¼g¤J¤u§@ªí
³o¼Ë­n§Ö«Ü¦h, ¨Ò¦p¼Ó¤Wªº¨Ò¤l
§@ªÌ: ML089    ®É¶¡: 2013-6-6 15:10

¦^´_ 22# sunnyso

¥H«e³£¬Oª½±µ§Q¥ÎÀx¦s®æ¹Bºâ¦s¨ú¡A¸g¹L³o¦¸¤ñ¸û¤~¤F¸Ñ¤£¦Pªº¤è¦¡®t²§¨º»ò¤j¡A¯u±oº¡¦³¦¬Ã¬ªº¡C
©Ò¥H­n°µ¬d¸ß¹BºâÁÙ¬O­n¥þ³¡¥ýŪ¦ÜÅܼư}¦C¡A¥þ³¡­pºâ¦n¤F¦A±NÅܼư}¦C¤@¦¸©Ê«ü¦Vµ¹Àx¦s®æ¡C

°õ¦æ®É¶¡®t«Ü¦h¡A°õ¦ætest2«á·|¦º·í6¤ÀÄÁ¡A­è¦n¥i¥H³Ü¤@ªM©@°Ø¡C
test1 1.4’
test2 299.3’
§@ªÌ: sunnyso    ®É¶¡: 2013-6-6 15:32

¦^´_ 24# ML089

¤£ª¾¹Dªº·|¥H¬°¹q¸£·í¾÷¤F, ±j¦æµ²§ôExcel·|¯}ÃaexcelÀÉ,³y¦¨·l¥¢
§@ªÌ: ML089    ®É¶¡: 2013-6-6 16:03

¦^´_ 22# sunnyso

¦p¦ó¦bSheet3°õ¦æ¥¨¶°test1¡A¸ê®Æ¼g¦ÜSheet1
§Ú¥[¤F¬õ¦â¦rµ²ªG°õ¦æ¿ù»~¡AÀ°¦£¬Ý¬Ý¿ù¦b­þ¸Ì¡A
¦bSheet1°õ¦æ¥¨¶°test1´N¥¿½T

    Sub test1()
    Dim i%, j%
    Dim Ar(1000, 1000) As Double
    For i = 0 To 1000
        For j = 0 To 1000
            Ar(i, j) = i * 4 + j
        Next j
    Next i
    Sheets("Sheet1").Range(Cells(1, 1), Cells(1001, 1001)) = Ar
End Sub

[attach]15187[/attach]
§@ªÌ: sunnyso    ®É¶¡: 2013-6-6 16:39

¥»©«³Ì«á¥Ñ sunnyso ©ó 2013-6-6 16:43 ½s¿è

¦^´_ 26# ML089

1. Change it to
Sheets("Sheet3").Range("A1").Resize(1000,1000) = Ar

2. or Change it to
     With Sheets("Sheet3")
        .Range(.Cells(1, 1), .Cells(1000, 1000)) = Ar
     End With

3. .xls - Excel 2003 and below  only have 256 Columns ("IV")
§@ªÌ: sunnyso    ®É¶¡: 2013-6-6 16:53

¦^´_ 18# ML089

MATCH ¥i¥H¥Î Scripting.Dictionary¨Ó¹ê²{
¸Õ¤U­±ªºcode
  1. Sub sonny3_dict()
  2.     t1 = Timer
  3.     Dim RowsCnt, m, SubTotalAr() As Double
  4.     Dim DataArea As Variant
  5.     Dim i%, j%
  6.     AllType = Array("AÃþ", "BÃþ", "CÃþ", "DÃþ", "EÃþ", "FÃþ", "GÃþ", "HÃþ", "IÃþ", "JÃþ")
  7.     AllMnth = Array("1¤ë", "2¤ë", "3¤ë", "4¤ë", "5¤ë", "6¤ë", "7¤ë", "8¤ë", "9¤ë", "10¤ë", "11¤ë", "12¤ë")
  8.     ReDim SubTotalAr(0 To UBound(AllType), 0 To 11)
  9.     Set TypeDict = CreateObject("Scripting.Dictionary")
  10.     Set MnthDict = CreateObject("Scripting.Dictionary")
  11.     For i = 0 To UBound(AllType)
  12.         TypeDict(AllType(i)) = i
  13.     Next i
  14.         For i = 0 To UBound(AllMnth)
  15.         TypeDict(AllMnth(i)) = i
  16.     Next i

  17.     Application.ScreenUpdating = False
  18.     With Sheets("­ì©l¸ê®Æ")
  19.         RowsCnt = .Range("A1").CurrentRegion.Rows.Count
  20.         DataArea = .Range("A2").Resize(RowsCnt - 1, 3)
  21.     End With
  22.     For m = 1 To UBound(DataArea)
  23.         i = TypeDict(DataArea(m, 1))
  24.         j = MnthDict(Month(DataArea(m, 2)) & "¤ë")
  25.         SubTotalAr(i, j) = SubTotalAr(i, j) + DataArea(m, 3)
  26.     Next m
  27.    
  28.     With Sheets("Á`ªí")
  29.         .Range("B4").Resize(UBound(AllType) + 1, 12) = SubTotalAr
  30.         .Range("B14:R14").FormulaR1C1 = "=SUM(R[-10]C:R[-1]C)"
  31.         .Range("N4:N13").FormulaR1C1 = "=SUM(RC[-12]:RC[-1])"
  32.         .Range("O4:R13").FormulaR1C1 = "=SUM(RC[-13]:RC[-11])"
  33.     End With
  34.     Application.ScreenUpdating = True
  35.     t2 = Timer
  36.     Sheets("­ì©l¸ê®Æ").Range("m7") = t2 - t1
  37.     MsgBox "¯Ó®É" & t2 - t1
  38. End Sub
½Æ»s¥N½X

§@ªÌ: ML089    ®É¶¡: 2013-6-6 23:10

¦^´_ 27# sunnyso

¦U¦¡ªº°õ¦æ®É¶¡¨ÃµL¤Ó¤j®t²§
Range(Cells(1,1),Cells(1001,1001)) À³¸Ó¬Oµ¥©ó Range("A1:ALL1000")¡A¥i¬O¤£¯à°õ¦æµLªk²z¸Ñ¡A¥u¦n°O¤U¨Ó¡C



¤U¦¡°õ¦æ¿ù»~
Sheets("Sheet1").Range(Cells(1,1),Cells(1001,1001))=Ar

¤U¦¡°õ¦æOK-1.5¬í
WithSheets("Sheet1")
.Range(.Cells(1,1),.Cells(1000,1000))=Ar
EndWith

¤U¦¡°õ¦æOK-1.5¬í
Sheets("Sheet1").Range("A1").Resize(1000,1000)=Ar

¤U¦¡°õ¦æOK-1.5¬í
Sheet1.[A1].Resize(1000,1000)=Ar

¤U¦¡°õ¦æOK-1.5¬í
Sheet1.[A1:ALL1000]=Ar

¤U¦¡°õ¦æOK-1.5¬í
Sheet1.Range("A1:ALL1000")=Ar
§@ªÌ: sunnyso    ®É¶¡: 2013-6-6 23:27

¥»©«³Ì«á¥Ñ sunnyso ©ó 2013-6-6 23:30 ½s¿è

¦^´_ 29# ML089

¦pªG§A¦bsheet3, ­n§â¸ê®Æ¼g¤Jsheet1

Sheets("Sheet1").Range(Sheets("Sheet1").Cells(1,1),Sheets("Sheet1").Cells(1001,1001))=Ar

¦]¬°cells(1, 1) ¬O sheets("sheet3").cells(1,1), ¤£¯à¥Î©ósheet1 ªºrange
§@ªÌ: ML089    ®É¶¡: 2013-6-6 23:33

¦^´_ 28# sunnyso

Scripting.Dictionary ¨S¦³ª½±µ¥Î°j°é¤ñ¸û¨Óªº§Ö
§@ªÌ: ML089    ®É¶¡: 2013-6-6 23:39

¦^´_ 30# sunnyso

·PÁÂ!¨ü±Ð
§Aªº¸ÑÄÀ§ÚÀ´¤F
§@ªÌ: sunnyso    ®É¶¡: 2013-6-6 23:45

¥»©«³Ì«á¥Ñ sunnyso ©ó 2013-6-7 00:00 ½s¿è

¦^´_ 31# ML089

·|¤ñMatch§Ö¶Ü?

¥t¥~,¦bNetbook¡]N470 1.83GHz)¤W¦r¨åªk§Ö¹L­~°é,
§@ªÌ: c_c_lai    ®É¶¡: 2013-6-7 06:17

¬Ý§¹1#ªþ¥ó¡A²Ä¤@¤ÏÀ³¬Oı±o²Ä¤TºØ¤èªkªºVBA CODE ¤¤ For¤Uªº¤£¤Ó¦n¡A­n¬°¥L¥­¤Ï !!! À³¸Ó¬O¹³c_c_lai¤j³o¼Ë ...
stillfish00 µoªí©ó 2013-6-4 20:05

ÁÂÁ«ü¾É¡I
Exit Sub ¾A«×ªº¸m¤J¡Aªº½T¯àÁ×±¼¤£¥²­nªº®ö¶O°j°é¡A
¥ÎÅܼƨӨú¥N½T¹ê¤]¦³¨Ç³\ªº§U¯q¡A¦pªG Month()
¨Ï¥ÎÀW²v¤jªº¸Ü¡A¨º´N·|¦³«Ü¤j¦a®Ä²v´£¤É¤F¡C
¦A¦¸¦V§A»¡ÁnÁÂÁ¡C
§@ªÌ: c_c_lai    ®É¶¡: 2013-6-7 06:25

¦^´_  sunnyso
ML089 µoªí©ó 2013-6-5 21:38

¦p¦¹­×§ï«á½T¹ê¦³¤£¿ù®Ä¯q´£¤É¡C
¦h¨¤«×ªº«äºû¥ç¯à¦ÒÅç»P¼W¶i§Ú­Ì«ä¦Òªº¯à¤O¡C
ÁÂÁ§A¡C
§@ªÌ: ML089    ®É¶¡: 2013-6-7 09:00

¦^´_ 33# sunnyso


¦bPC¤Wi5 2.8GHz RAM-4G¤W³t«×§ÖºC¤ñ¸û
°j°é¤ñ¸û > ¦r¨å¬d¸ß > MATCH¬d¸ß

¤£¦PµwÅ馳¤£¦Pªº®ÄªG¡A¬Æ¦Ü²Ä¤G¦¸°õ¦æ³£¤ñ²Ä¤@¦¸°õ¦æ§Ö¡A¦ý¤j­P¤è¦V¥i¥HÂǥѳo¦¸ÅéÅçÀò±o¤@¨ÇÄ_¶Q¸gÅç¡C
§@ªÌ: sunnyso    ®É¶¡: 2013-6-7 10:13

¦^´_ 36# ML089

²Ä¤G¦¸°õ¦æ¦]爲¦³Cache©Ò¥H·|¤ñ¸û§Ö¡A ¥Î¤U­±ªºcode ¥i¥H¦b­pºâµ²§ô«á²M°£Cache¡A but only for Excel 2007 and above

added a Class Module called AppEvents with code like this:
  1. Option Explicit
  2. Private WithEvents App As Application
  3. Private Sub Class_Initialize()
  4. Set App = Application
  5. End Sub
  6. Private Sub App_AfterCalculate()
  7. ClearCache
  8. End Sub
½Æ»s¥N½X
Only Excel 2007 and later have the AfterCalculate event which will be used to empty the cache after each calculate
This code is ignored in Excel 2003 and earlier: since the AfterCalculate event does not exist it never gets called but still compiles OK.
§@ªÌ: sunnyso    ®É¶¡: 2013-6-30 22:46

¦^´_ 18# ML089

¦^´_  sunnyso
A CODE ­×§ï¬° B CODE¡A°õ¦æ®É¶¡¥Ñ 0.257¬íÅܺC¬°1.304¬í¡AÅܱo«ÜºC
¦bVBA¤º¥Î¬¡­¶Ã¯¨ç¼Æ·|¼W¥[«Ü¦h®É¶¡
¤£ª¾VBA¤º¦³µL¨ä¥L¥i¨ú¥NMATCH¨ç¼Æ
ML089 µoªí©ó 2013-6-6 09:29


¤£¥Î°j°é¡A¤£¥ÎWorksheet¨ç¼Æ¡]matchµ¥¡^¡A§PÂ_¬Yelement¦b°}¦C¤¤¦ì¸m
¨Ò¦p
  1. Sub ss_test()
  2.     alltype = Array("AÃþ", "BÃþ", "CÃþ", "DÃþ", "EÃþ", "FÃþ", "GÃþ", "HÃþ", "IÃþ", "JÃþ")
  3.     aj = "DÃþ"
  4.     Debug.Print UBound(Split(Split(Join(alltype, "|"), aj)(0), "|")) + 1
  5.    
  6.     Stop
  7. End Sub
½Æ»s¥N½X

§@ªÌ: ML089    ®É¶¡: 2013-6-30 23:41

¦^´_ 38# sunnyso


    ¦n·Qªk
§@ªÌ: sunnyso    ®É¶¡: 2013-6-30 23:46

¦^´_ 39# ML089

¦³bug¡A §ï爲
  1. Sub ss_test()
  2.     alltype = Array("AÃþ", "BÃþ", "CÃþ", "DÃþ", "EÃþ", "FÃþ", "GÃþ", "HÃþ", "IÃþ", "JÃþ")
  3.     aj = "DÃþ"
  4.     Debug.Print UBound(Split(Split(¡§ ¡¨ & Join(alltype, "|"), aj)(0), "|"))
  5.    
  6.     Stop
  7. End Sub
½Æ»s¥N½X

§@ªÌ: sunnyso    ®É¶¡: 2013-6-30 23:59

¦^´_ 39# ML089

¦n¹³ÁÙ¬O loop §Ö
  1. Sub sonny3_v3() 'VBA split+join
  2.     t1 = Timer
  3.     Dim RowsCnt, m, SubTotalAr() As Double
  4.     Dim DataArea As Variant
  5.     Dim i%, j%
  6.     AllType = " AÃþ|BÃþ|CÃþ|DÃþ|EÃþ|FÃþ|GÃþ|HÃþ|IÃþ|JÃþ"
  7.     ReDim SubTotalAr(0 To 9, 0 To 11)
  8.     Application.ScreenUpdating = False
  9.     With Sheets("­ì©l¸ê®Æ")
  10.         RowsCnt = .Range("A1").CurrentRegion.Rows.Count
  11.         DataArea = .Range("A2").Resize(RowsCnt - 1, 3)
  12.         For m = 1 To UBound(DataArea)
  13.             i = UBound(Split(Split(AllType, DataArea(m, 1))(0), "|"))
  14.             j = -1
  15.             Do
  16.                 j = j + 1
  17.             Loop Until Month(DataArea(m, 2)) = (j + 1)
  18.             SubTotalAr(i, j) = SubTotalAr(i, j) + DataArea(m, 3)
  19.         Next m
  20.     End With
  21.    
  22.     With Sheets("Á`ªí")
  23.         .Range("B4").Resize(9 + 1, 12) = SubTotalAr
  24.         .Range("B14:R14").FormulaR1C1 = "=SUM(R[-10]C:R[-1]C)"
  25.         .Range("N4:N13").FormulaR1C1 = "=SUM(RC[-12]:RC[-1])"
  26.         .Range("O4:R13").FormulaR1C1 = "=SUM(RC[-13]:RC[-11])"
  27.     End With
  28.     Application.ScreenUpdating = True
  29.     t2 = Timer
  30.     MsgBox "¯Ó®É" & t2 - t1
  31. End Sub
½Æ»s¥N½X

§@ªÌ: ML089    ®É¶¡: 2013-7-1 09:51

¦^´_ 41# sunnyso

§Ú´ú¸Õµ²ªG¤]¬O¤@¼Ë
UBound(Split(Split( ¥Î¤F3­Ó¨ç¼Æ¡ASplit( ³oºØ¤å¦r¨ç¼ÆÀ³¸Ó¤]¤ñ¸ûºC

³o¨Ò¤l¾Ç²ß¨ì¡G
EXCEL ¨ç¼Æ ¤ñ VBA¨ç¼ÆºC«Ü¦h
¤å¦r¨ç¼Æ ¤ñ ¼Æ¦r¨ç¼ÆºC
´î¤Ö°j°é¾A®É¸õ¥X
´î¤Ö¨ç¼Æ¨Ï¥Î¶q
§@ªÌ: sunnyso    ®É¶¡: 2013-7-1 09:53

¥»©«³Ì«á¥Ñ sunnyso ©ó 2013-7-1 09:56 ½s¿è

¦^´_ 42# ML089

§¹¥þ¦P·N
¥t¥[

VBA¥Î°}¦C¡A´î¤ÖŪ¼gworksheet¦¸¼Æ

Worksheet ´î¤Ö¥Î°}¦C¤½¦¡ ¡]ctrl+shift+Enter)
§@ªÌ: sunnyso    ®É¶¡: 2013-7-1 10:14

¥»©«³Ì«á¥Ñ sunnyso ©ó 2013-7-1 10:24 ½s¿è
¦^´_  ML089

§¹¥þ¦P·N
¥t¥[

VBA¥Î°}¦C¡A´î¤ÖŪ¼gworksheet¦¸¼Æ

Worksheet ´î¤Ö¥Î°}¦C¤½¦¡ ¡]ctrl+shift+Enter)

sunnyso µoªí©ó 2013-7-1 09:53


¤£­nª[µø»²§UÄæ¡A¦]爲°}¦C¤½¦¡¤ñ»²§UÄæºC

°}¦C¤½¦¡¾A¦X¤p«¬­pºâ¡A¡]©M¾Ç²ß½m¥\¡^
§@ªÌ: ML089    ®É¶¡: 2013-7-5 12:23

¦^´_ 43# sunnyso


VBA±N¸ê®Æ¤@¦¸Åª¤J°}¦C¦A°µ­pºâ¤ñ¸û§Ö¡A¤£ª¾¹D°}¦C¤j¤p¦³µL­­¨î¡C
¦pªG¸ê®Æ¶q«Ü¤j¶W¹L°}¦C­­¨î®É¦³µL³B²z¤è¦¡¡C
¥Ø«e§Ú·Q±N9­Ó¤å¦rÀÉ(¨C­ÓÀɮ׬ù3~5¸U¦æ¡A¨C¦æ80¦r)¦P®Éª½±µÅª¤J°}¦C¦A¨Ó³B²z¡A½Ð±Ð³oºØ¤è¦¡¬O§_¥i¦æ¡C
§@ªÌ: stillfish00    ®É¶¡: 2013-7-5 13:43

¦^´_ 45# ML089
­­¨îÀ³¸Ó´N¬O°O¾ÐÅé¤j¤p§a¡A§â¸ê®ÆŪ¨ì°}¦C²z½×¤W´N¬OŪ¨ì°O¾ÐÅ餺¡A¥Îstop¤¤Â_¨ÃÆ[¹î¤u§@ºÞ²z­û>³B²zµ{§Ç>Excel.exe©Ò¦ûªº°O¾ÐÅé¤j¤p¥i¥H±oª¾¡C¦ý°O¾ÐÅé¤S¤À¶¥¼h:§Ö¨ú¡B¹êÅé¡BµêÀÀ¡A¦pªGŪ¤J¸ê®Æ¹L¤j¦Ó¨Ï¥Î¨ìµêÀÀ°O¾ÐÅé(¨ä¹ê´N¬OµwºÐ¤À­¶ÀÉ)¡A³t«×´N¨S­ì¥»¨º»ò§Ö¤F¡C
§@ªÌ: ML089    ®É¶¡: 2013-7-5 17:08

¦^´_ 46# stillfish00

ÁÂÁ¦^ÂÐ

¬d¸ß¤U¦Cºô­¶
http://msdn.microsoft.com/zh-tw/library/b388cb5s(v=vs.80).aspx

¸Ì­±»¡¨ì¡A¨C­Ó°}¦C¤§ºû«×ªø«×³£¨ü­­©ó Integer ¸ê®Æ«¬§Oªº³Ì¤j­È¡A¤]´N¬O (2 ^ 31) - 1¡AµM¦Ó¡A°}¦C¤§Á`¤j¤p¤]¦P®É¨ü­­©ó¨t²Î¥i¥Îªº°O¾ÐÅé¡C
©Ò¥H»¡¥i«Å§i¼Æ¶qÀ³¸Ó¤£¬O°ÝÃD¡A¥i¬O¨ü­­©ó¨t²Î¥i¥Îªº°O¾ÐÅé¡C
«áÄò³B²z®É¯uªº¹J¨ì°ÝÃD¦A¨Ó½Ð±Ð¤j®a¡C


------------------------------------------------------------------------
Visual Basic ¤¤ªº°}¦C¤j¤p

Visual Studio 2005 ¨ä¥Lª©¥» ¥»¥DÃD©|¥¼±µ¨üµû¤À - ¬°³o­Ó¥DÃDµû¤À
°}¦C¤j¤p¬°¨ä©Ò¦³ºû«× (Dimension) ªø«×¤§­¼¿n¡C¥¦¥Nªí¥Ø«e¥]§t©ó°}¦C¤¤ªº¤¸¯ÀÁ`¼Æ¡C
¤U¦C½d¨Ò«Å§i¤@­Ó¤Tºû°}¦C¡J
Dim prices(3, 4, 5) As Long
ÅÜ¼Æ prices °}¦Cªº¾ãÅé¤j¤p¬° (3 + 1) x (4 + 1) x (5 + 1) = 120¡C

°}¦C¤j¤p¦Ò¼{¨Æ¶µ
³B²z°}¦C¤j¤p®É¡A½Ðª`·N´XÂI¡J
ºû«×ªø«×
¨C­Óºû«×ªº¯Á¤Þ³£ ¥H 0 ¬°°_ÂI¡A¤]´N¬O¥¦ªº½d³ò¬O¥Ñ 0 ¨ì¥¦ªº¤W­­ (Upper Bound)¡C¦]¦¹¡A«ü©wºû«×ªºªø«×·|¤ñ¸Óºû«×ªº«Å§i¤W­­¦h 1¡C

ªø«×­­¨î
¨C­Ó°}¦C¤§ºû«×ªø«×³£¨ü­­©ó Integer ¸ê®Æ«¬§Oªº³Ì¤j­È¡A¤]´N¬O (2 ^ 31) - 1¡CµM¦Ó¡A°}¦C¤§Á`¤j¤p¤]¦P®É¨ü­­©ó¨t²Î¥i¥Îªº°O¾ÐÅé¡C­Y±z¸Õ¹Ï¹ïÁ`¤j¤p¶W¹L¥i¥Îªº RAM ¤§°}¦C¶i¦æªì©l¤Æ¡ACommon Language Runtime ±NÂY¦^ OutOfMemoryException ¨Ò¥~ª¬ªp¡C

¤j¤p¤Î¤¸¯À¤j¤p
°}¦C¤j¤p»P¨ä¤¸¯Àªº¸ê®Æ«¬§OµLÃö¡C¤j¤p¥Ã»·¬O«ü¤¸¯ÀªºÁ`¼Æ¡A¦Ó¤£¬O¥¦­Ì©óÀx¦sÅ餤©Ò¦ûªº¦ì¤¸²Õ¡C
°O¾ÐÅé®ø¯Ó¶q
¹ï°}¦C¦b°O¾ÐÅ餤ªºÀx¦s¤è¦¡°µ¥ô¦ó°²³]³£¬O¤£¦w¥þªº¡CÀx¦sÅé·|¦]¤£¦P¸ê®Æ¼e«×ªº¥­¥x¦Ó¦³®t²§¡A©Ò¥H¬Û¦P°}¦C©ó 64 ¦ì¤¸¨t²Î¤W©Ò¦û°O¾ÐÅé±N¸û 32 ¦ì¤¸¨t²Î¨Óªº¦h¡C·í±zªì©l¤Æ°}¦C®É¡AÀHµÛ¨t²Î²ÕºA¤£¦P¡ACommon Language Runtime (CLR) ·|«ü¬£Àx¦sÅéºÉ¥i¯à±N¤¸¯À¦s©ñ¦b¤@°_¡A©Î¬O®Ú¾Ú¹êÅéµwÅé¬É­­±N¥¦­Ì¥þ³¡¥[¥H½Õ¾ã¡C¦P®É¡A°}¦C»Ý­n¯Ó¥ÎÀx¦sÅé¥H¨Ñ¨ä±±¨î¸ê°T¨Ï¥Î¡A¦¹®ø¯Ó¶q·|ÀHµÛºû«×¼W¥[¦Ó¼W¥[¡C
§@ªÌ: sunnyso    ®É¶¡: 2013-7-5 18:29

¦^´_ 47# ML089

·PÁÂML089,
§@ªÌ: stillfish00    ®É¶¡: 2013-7-5 19:33

¦^´_ 47# ML089
«D±`¸ÔºÉªº¸ê°T¡AÁÂÁ¡A¤S¾Ç¨ì¤F¤£¤Ö¡C
§@ªÌ: GBKEE    ®É¶¡: 2013-7-6 05:51

¦^´_ 47# ML089
   
³B²z°}¦C¤j¤p®É¡A½Ðª`·N´XÂI¡J
ºû«×ªø«×
¨C­Óºû«×ªº¯Á¤Þ³£ ¥H 0 ¬°°_ÂI¡A¤]´N¬O¥¦ªº½d³ò¬O¥Ñ 0 ¨ì¥¦ªº¤W­­ (Upper Bound)¡C¦]¦¹¡A«ü©wºû«×ªºªø«×·|¤ñ¸Óºû«×ªº«Å§i¤W­­¦h 1¡C
¤]¥i¥H¬O³o¼Ëªº


[attach]15376[/attach]
§@ªÌ: ML089    ®É¶¡: 2013-7-6 09:17

¦^´_ 50# GBKEE

ÁÂÁ¸ɥR»¡©ú
°}¦Cªº¯Á¤Þ¤W¤U«ü¼Ð¤]¥i¥H¦Û­q




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