- 帖子
- 4901
- 主題
- 44
- 精華
- 24
- 積分
- 4916
- 點名
- 118
- 作業系統
- Windows 7
- 軟體版本
- Office 20xx
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台北
- 註冊時間
- 2010-4-30
- 最後登錄
- 2025-5-15
               
|
2#
發表於 2012-5-5 16:41
| 只看該作者
回復 1# mmggmm - Private Sub Worksheet_Change(ByVal Target As Range) '月結
- If Intersect(Target, Union([A1], [C1])) Is Nothing Then Exit Sub
- Set d = CreateObject("Scripting.Dictionary")
- MyDay = [A1] & [C1]
- With Sheets("Main")
- For Each a In .Range(.[A2], .[A2].End(xlDown))
- If Format(a, "yyyym") = MyDay Then
- If IsEmpty(d(a.Offset(, 1).Value)) Then
- d(a.Offset(, 1).Value) = Array(a.Offset(, 1).Value, a.Offset(, 2).Value, a.Offset(, 3).Value, a.Offset(, 4).Value)
- Else
- ar = d(a.Offset(, 1).Value)
- ar(2) = ar(2) + a.Offset(, 3): ar(3) = ar(3) + a.Offset(, 4)
- d(a.Offset(, 1).Value) = ar
- Erase ar
- End If
- End If
- Next
- Me.Range("A1").CurrentRegion.Offset(3).ClearContents
- If d.Count > 0 Then Me.[A3].Resize(d.Count, 4) = Application.Transpose(Application.Transpose(d.items))
- End With
- End Sub
複製代碼- Private Sub Worksheet_Change(ByVal Target As Range) '年結
- If Intersect(Target, [A1]) Is Nothing Then Exit Sub
- Set d = CreateObject("Scripting.Dictionary")
- MyYear = [A1]
- With Sheets("Main")
- For Each a In .Range(.[A2], .[A2].End(xlDown))
- If Year(a) = MyYear Then
- If IsEmpty(d(a.Offset(, 1).Value)) Then
- d(a.Offset(, 1).Value) = Array(a.Offset(, 1).Value, a.Offset(, 2).Value, a.Offset(, 3).Value, a.Offset(, 4).Value)
- Else
- ar = d(a.Offset(, 1).Value)
- ar(2) = ar(2) + a.Offset(, 3): ar(3) = ar(3) + a.Offset(, 4)
- d(a.Offset(, 1).Value) = ar
- Erase ar
- End If
- End If
- Next
- Me.Range("A1").CurrentRegion.Offset(3).ClearContents
- If d.Count > 0 Then Me.[A3].Resize(d.Count, 4) = Application.Transpose(Application.Transpose(d.items))
- End With
- End Sub
複製代碼 |
|