|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
工作表事件
- Private Sub Worksheet_Change(ByVal Target As Range)
- Application.EnableEvents = False
- If Target.Address = "$B$3" Or Target.Address = "$E$3" Then
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- With Sheets("Sheet1 (2)")
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .[a1].Resize(r, 22)
- End With
- ReDim zrr(1 To r, 1 To 10)
- rq1 = Me.[b3].Value
- rq2 = Me.[e3].Value
- For i = 4 To UBound(arr)
- rq = CDate(arr(i, 10))
- If rq >= rq1 And rq <= rq2 Then
- s = arr(i, 2)
- d(s) = d(s) + 1
- s = arr(i, 12)
- If Not d1.exists(s) Then
- m = m + 1
- d1(s) = m
- zrr(m, 1) = s
- For j = 16 To UBound(arr, 2)
- zrr(m, j - 14) = arr(i, j)
- Next
- Else
- r = d1(s)
- For j = 16 To UBound(arr, 2)
- zrr(r, j - 14) = zrr(r, j - 14) + arr(i, j)
- Next
- End If
- End If
- Next
- Me.[g3] = d.Count & "个"
- d.RemoveAll
- For i = 4 To UBound(arr)
- rq = CDate(arr(i, 10))
- If rq >= rq1 And rq <= rq2 Then
- s = arr(i, 2) & "-" & arr(i, 5)
- If Not d.exists(s) Then
- d(s) = arr(i, 4)
- End If
- End If
- Next
- Sum = 0
- For Each k In d.keys
- Sum = Sum + d(k)
- Next
- If m > 0 Then
- Me.[h3] = Sum & "个"
- Me.[a5].Resize(1000, 9) = ""
- Me.[a5].Resize(m, 9) = zrr
- For i = 5 To m + 4
- Me.Cells(i, "i") = Application.Sum(Me.Cells(i, 2).Resize(, 7))
- Next
- End If
- Set d = Nothing
- End If
- Application.EnableEvents = True
- End Sub
复制代码
|
|