- 帖子
- 472
- 主題
- 5
- 精華
- 0
- 積分
- 485
- 點名
- 0
- 作業系統
- Windows
- 軟體版本
- MS Office
- 閱讀權限
- 100
- 性別
- 男
- 來自
- 香港
- 註冊時間
- 2010-7-4
- 最後登錄
- 2014-12-28

|
本帖最後由 kimbal 於 2013-5-31 01:40 編輯
回復 1# yliu - Private Sub CommandButton2_Click()
- Application.ScreenUpdating = False
- Application.Calculation = xlCalculationManual
- Dim rowcnt As Long
- Dim i As Long
- Dim lngVlookupRow As Long
- Dim lngCurrenMonth As Long
- Dim lngCurrValue As Long
- '清理舊數據
- Sheets("總表").Activate
- Sheets("總表").Range("A3").CurrentRegion.Offset(1, 1).Clear
- Sheets("原始資料").Activate
- With Sheets("原始資料")
- rowcnt = .Cells(1, 1).CurrentRegion.Rows.Count
- For i = 1 To rowcnt
- lngCurrenMonth = 0
- If IsDate(.Cells(i, 2)) Then
- lngCurrenMonth = Month(.Cells(i, 2)) '當行月份
- End If
- If lngCurrenMonth > 0 And Not (IsError(Application.Match(.Cells(i, 1), Sheets("總表").Range("A:A"), 0))) Then
- lngVlookupRow = Application.Match(.Cells(i, 1), Sheets("總表").Range("A:A"), 0) '當行類型在總表行數
- lngCurrValue = .Cells(i, 3)
- With Sheets("總表").Cells(lngVlookupRow, lngCurrenMonth + 1) '放數據到總表上
- .Value = .Value + lngCurrValue
- End With
- End If
- Next
-
- End With
- Application.Calculation = xlCalculationAutomatic
- Application.ScreenUpdating = True
- End Sub
複製代碼 |
|