- ©«¤l
- 2035
- ¥DÃD
- 24
- ºëµØ
- 0
- ¿n¤À
- 2031
- ÂI¦W
- 0
- §@·~¨t²Î
- Win7
- ³nÅ骩¥»
- Office2010
- ¾\ŪÅv
- 100
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2012-3-22
- ³Ì«áµn¿ý
- 2024-2-1
|
¦^´_ 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- Sub Ex_Match_Case() ' Match Case
- Dim RowsCnt As Long, i As Long, SubTotalAr() As Double
- Dim t1 As Variant, t2 As Variant, AllType As Variant
- Dim DataArea As Variant, Atype As Integer
- Dim lngCurrenMonth As Long, lngCurrValue As Long
- t1 = Timer
- Application.ScreenUpdating = False
- ' Application.Calculation = xlCalculationManual
- AllType = Array("AÃþ", "BÃþ", "CÃþ", "DÃþ", "EÃþ", "FÃþ", "GÃþ", "HÃþ", "IÃþ", "JÃþ")
- ReDim SubTotalAr(0 To UBound(AllType), 0 To 16)
- ' ²M²z¼ƾÚ
- Sheets("Á`ªí").Activate
- Sheets("Á`ªí").Range("A3").CurrentRegion.Offset(1, 1).Clear
- Sheets("ì©l¸ê®Æ").Activate
- With Sheets("ì©l¸ê®Æ")
- RowsCnt = .Cells(1, 1).CurrentRegion.Rows.Count
- DataArea = .Range("A2").Resize(RowsCnt - 1, 3)
-
- For i = 1 To UBound(DataArea)
- lngCurrenMonth = 0
- If IsDate(DataArea(i, 2)) Then
- lngCurrenMonth = Month(DataArea(i, 2)) ' ·í¦æ¤ë¥÷
- End If
-
- If lngCurrenMonth > 0 Then
- lngCurrValue = DataArea(i, 3)
-
- For Atype = 0 To UBound(AllType) ' AÃþ To JÃþ
- If DataArea(i, 1) = AllType(Atype) Then ' Jan To Dec
- SubTotalAr(Atype, lngCurrenMonth - 1) = SubTotalAr(Atype, lngCurrenMonth - 1) + lngCurrValue
- SubTotalAr(Atype, 12) = SubTotalAr(Atype, 12) + lngCurrValue ' ²Öp
- SubTotalAr(Atype, 13 + Int(lngCurrenMonth / 3.2)) = SubTotalAr(Atype, 13 + Int(lngCurrenMonth / 3.2)) + lngCurrValue
- ' °£¥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)¡A6 (Int(1.875 ))=1)¡A ' ²Ä¤G©u
- ' 7 (Int(2.1875))= 2)¡A8 (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
- ' *************************************************************************************
- End If
- Next Atype
- End If
- Next i
- End With
-
- With Sheets("Á`ªí")
- .Range("B4").Resize(UBound(AllType) + 1, 17) = SubTotalAr
- ' RowsCnt = .[A3].End(xlDown).Row
- ' For i = 2 To 18
- ' .Cells(RowsCnt, i) = WorksheetFunction.Sum(.Range(Chr(64 + i) & 4 & ":" & Chr(64 + i) & (RowsCnt - 1))) ' ¦Xp
- ' Next i
- .Range("B14:R14").FormulaR1C1 = "=SUM(R[-10]C:R[-1]C)"
- End With
-
- ' Application.Calculation = xlCalculationAutomatic
- Application.ScreenUpdating = True
- t2 = Timer
- ' MsgBox "¯Ó®É" & t2 - t1
- Sheets("ì©l¸ê®Æ").[F11] = "¯Ó®É¡G " & CDbl(t2 - t1)
- End Sub
½Æ»s¥N½X B. ¸g´ú¸Õ¡A®Ä¯q³Ì¨Îªºµ{¦¡¼Ò²Õ¡G- Sub Ex_VBA_Array() ' VBA Code DataArea Array
- Dim RowsCnt As Long, m As Long, SubTotalAr() As Double
- Dim t1 As Variant, t2 As Variant, AllType As Variant
- Dim DataArea As Variant
- Dim i%, j%
-
- t1 = Timer
- AllType = Array("AÃþ", "BÃþ", "CÃþ", "DÃþ", "EÃþ", "FÃþ", "GÃþ", "HÃþ", "IÃþ", "JÃþ")
- ReDim SubTotalAr(0 To UBound(AllType), 0 To 11)
- Application.ScreenUpdating = False
-
- ' ²M²z¼ƾÚ
- ' Sheets("Á`ªí").Activate
- Sheets("Á`ªí").Range("A3").CurrentRegion.Offset(1, 1).Clear
-
- With Sheets("ì©l¸ê®Æ")
- RowsCnt = .Range("A1").CurrentRegion.Rows.Count
- DataArea = .Range("A2").Resize(RowsCnt - 1, 3)
-
- For m = 1 To UBound(DataArea)
- For i = 0 To UBound(AllType) ' AÃþ To JÃþ
- If DataArea(m, 1) = AllType(i) Then ' Jan To Dec
- SubTotalAr(i, Month(DataArea(m, 2)) - 1) = SubTotalAr(i, Month(DataArea(m, 2)) - 1) + DataArea(m, 3)
- End If
- Next i
- Next m
- End With
-
- With Sheets("Á`ªí")
- .Range("B4").Resize(UBound(AllType) + 1, 12) = SubTotalAr
- .Range("N4:N13").FormulaR1C1 = "=SUM(RC[-12]:RC[-1])"
- For i = 0 To 3
- ' .Range(Chr(79 + i) & 4 & ":" & Chr(79 + i) & 13).FormulaR1C1 = "=SUM(RC[-" & (13 - i * 2) & "]:RC[-" & (11 - i * 2) & "])"
- .Range(Chr(79 + i) & 4).Resize(UBound(AllType) + 1).FormulaR1C1 = "=SUM(RC[-" & (13 - i * 2) & "]:RC[-" & (11 - i * 2) & "])"
- .Range(Chr(79 + i) & 4).Resize(UBound(AllType) + 1) = .Range(Chr(79 + i) & 4).Resize(UBound(AllType) + 1).Value
- Next i
- .Range("B14:R14").FormulaR1C1 = "=SUM(R[-10]C:R[-1]C)"
- End With
- Application.ScreenUpdating = True
- t2 = Timer
- ' MsgBox "¯Ó®É" & t2 - t1
- Sheets("ì©l¸ê®Æ").[F3] = "¯Ó®É¡G " & CDbl(t2 - t1)
- End Sub
½Æ»s¥N½X ¥H¤W¨â²Õ¼Ò²Õ¡A§¡¨Ï¥Î 70 µ§¡B¥H¤Î 52,993 µ§¤§¸ê®Æ (sunnyso «e½ú´£¨Ñ) ´ú¸Õ¹L¡C
©p¥i¥H¦Û¦æ´ú´ú¬Ý¡C |
|