- 帖子
- 2035
- 主題
- 24
- 精華
- 0
- 積分
- 2031
- 點名
- 0
- 作業系統
- Win7
- 軟體版本
- Office2010
- 閱讀權限
- 100
- 性別
- 男
- 註冊時間
- 2012-3-22
- 最後登錄
- 2024-2-1
|
7#
發表於 2013-5-31 16:23
| 只看該作者
回復 kimbal
謝謝kimbal.
但出現執行階段錯誤’13’: 型態不符合
偵錯在: With Sheets("總表").Cells( ...
yliu 發表於 2013-5-31 12:30 
回復 2# kimbal
不好意思,我稍微添加了幾行,希望您等能笑納!- Private Sub Ex()
- Dim rowcnt As Long, i As Long
- Dim lngVlookupRow As Long, lngCurrenMonth As Long, lngCurrValue As Long
- Application.ScreenUpdating = False
- Application.Calculation = xlCalculationManual
- ' 清理舊數據
- Sheets("總表").Activate
- Sheets("總表").Range("A3").CurrentRegion.Offset(1, 1).Clear
- Sheets("原始資料").Activate
- With Sheets("原始資料")
- rowcnt = .Cells(1, 1).CurrentRegion.Rows.Count
- For i = 2 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 = .Cells(lngVlookupRow, lngCurrenMonth + 1).Value + lngCurrValue ' 放數據到總表上
- .Cells(lngVlookupRow, "N") = .Cells(lngVlookupRow, "N") + lngCurrValue
- .Cells(lngVlookupRow, Chr(79 + Int(lngCurrenMonth / 4))) = .Cells(lngVlookupRow, Chr(79 + Int(lngCurrenMonth / 4))) + lngCurrValue
- End With
- End If
- Next
- End With
-
- With Sheets("總表")
- rowcnt = .[A3].End(xlDown).Row
- For i = 2 To 18
- .Cells(rowcnt, i) = WorksheetFunction.Sum(.Range(Chr(64 + i) & 4 & ":" & Chr(64 + i) & (rowcnt - 1)))
- Next i
- End With
-
- Application.Calculation = xlCalculationAutomatic
- Application.ScreenUpdating = True
- End Sub
複製代碼 |
|