使用宏实现透视表部分功能,将AB列数据合并统计.

功能:1.筛选B列;2.将A列中的值按照筛选后的结果进行合计.

这个特殊点是按照月日进行筛选的.

 

Sub count_a()
Dim sh As Worksheet
Set sh = ActiveSheet
Range("C2:D" & [D65536].End(3).Row).Clear
For line_b = 2 To [B65536].End(3).Row
If Len(Cells(line_b, "B").Value) <> 10 Then
'Cells(line_b, "B").Value = Left(Cells(line_b, "B").Value, 5) & "0" & Right(Cells(line_b, "B").Value, 4)
Cells(line_b, "B").Value = Format(Cells(line_b, "B").Value, "YYYY/MM/DD")
End If
Next

arr = ActiveSheet.Range("B2:B" & [B65536].End(3).Row)
Set dict = CreateObject("scripting.dictionary")
For j = 2 To UBound(arr)
If LenB(Right(arr(j, 1), 5)) > 0 Then
dict(Right(arr(j, 1), 5)) = ""
End If
Next j

k = dict.keys
Dim count_a
For dict_i = 0 To dict.Count - 1
count_a = 0
Key = k(dict_i)
'MsgBox Key
Cells(dict_i + 2, "C").Value = Format(Key, "MM/DD")
For line_a = 2 To [a65536].End(3).Row
If Right(Cells(line_a, "B").Value, 5) = Key Then
count_a = count_a + Cells(line_a, "A").Value
End If
Next
Cells(dict_i + 2, "D").Value = count_a

Next


End Sub

posted @   一路漂泊  阅读(486)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示