|
- Sub ykcbf()
- Dim b(1 To 3), sum(1 To 3), st(1 To 3) '定义变量
- r = Cells(Rows.Count, "a").End(3).Row '计算数据行数
- arr = [a1].Resize(r, 4) '将数据读入数组
- Set d = CreateObject("Scripting.Dictionary") '创建字典对象
- Set d1 = CreateObject("Scripting.Dictionary")
- Set d2 = CreateObject("Scripting.Dictionary")
- Set d3 = CreateObject("Scripting.Dictionary")
- tod = Date '获取今天日期
- yf = Month(tod) '获取本月月份
- nf = Year(tod) '获取本年年份
- For i = 2 To UBound(arr) '遍历数据数组
- s = arr(i, 2) '获取当前行的名称
- rq = CDate(arr(i, 1)) '获取当前行的日期
- d(s) = "" '将名称存入字典
- summ = summ + arr(i, 4) '累加总金额
- If rq = tod Then '如果日期是今天
- d1(s) = "" '将名称存入今天的字典
- sum(1) = sum(1) + arr(i, 4) '累加今天的金额
- End If
- If Month(rq) = yf Then '如果日期是本月
- d2(s) = "" '将名称存入本月的字典
- sum(2) = sum(2) + arr(i, 4) '累加本月的金额
- End If
- If Year(rq) = nf Then '如果日期是本年
- d3(s) = "" '将名称存入本年的字典
- sum(3) = sum(3) + arr(i, 4) '累加本年的金额
- End If
- Next
- For x = 1 To 3 '遍历3个汇总结果
- Cells(x + 1, 12) = sum(x) '将金额输出在表格中
- Next
- Cells(2, 11) = d1.Count '输出今天的名称数量
- Cells(3, 11) = d2.Count '输出本月的名称数量
- Cells(4, 11) = d3.Count '输出本年的名称数量
- Cells(5, 11) = d.Count '输出总的名称数量
- Cells(5, 12) = summ '输出总金额
- End Sub
复制代码 |
|