当前位置:网站首页>Excel VBA:按日期汇总计算输出结果(sumif)
Excel VBA:按日期汇总计算输出结果(sumif)
2022-07-26 04:57:00 【Avasla】
问题场景
1)按日期将C列的金额累计汇总
2)按日期和"支出/收入"汇总每日金额
PS:直接输出结果,不需要公式
参数定义&函数说明
参数定义:
- Range格式定义汇总范围
- Long 格式定义参数。因为后续参数长度会超过32767,所以选取Long。
- Long(长整型)变量存储为带符号的 32 位(4 字节)数字,值范围从 -2,147,483,648 到 2,147,483,647。
- Integer(整形)Integer 变量存储为 16 位(2 字节)数字,值范围为 -32,768 至 32,767。
函数使用:
- WorksheetFunction.Round (expression, [ numdecimalplaces ])
- WorksheetFunction.SumIfs (Arg1、Arg2、Arg3…)
1)结果代码:每日累计汇总金额
Sub 每日累计汇总金额()
Application.ScreenUpdating = False
Dim sumRange As Range
Dim criteriaRange_date As Range
Dim e As Long, f As Long, g As Long
'定义Range
Set sumRange = Sheets("Sheet1").Range("C2:C31") '金额
Set criteriaRange_date = Sheets("Sheet1").Range("A2:A31") '日期
Sheets("Sheet1").Select
e = Range("K1048573").End(xlUp).Row ' 初始行数 - 1
f = Range("J1048573").End(xlUp).Row '结束行数
'更新
For g = e + 1 To f
'累计
Sheets("Sheet1").Cells(g, 11) = WorksheetFunction.Round(WorksheetFunction.SumIfs(sumRange, criteriaRange_date, "<=" & Cells(g, 10)), 2)
Next g
End Sub
2)结果代码:每日支出收入金额
Sub 每日支出收入金额()
Application.ScreenUpdating = False
Dim sumRange As Range
Dim criteriaRange As Range
Dim criteriaRange_date As Range
Dim e As Long, f As Long, g As Long
'定义Range
Set sumRange = Sheets("Sheet1").Range("C2:C31") '金额
Set criteriaRange = Sheets("Sheet1").Range("D2:D31") '分类
Set criteriaRange_date = Sheets("Sheet1").Range("A2:A31") '日期
Sheets("Sheet1").Select
e = Range("O1048573").End(xlUp).Row ' 初始行数 - 1
f = Range("N1048573").End(xlUp).Row '结束行数
'更新
For g = e + 1 To f
'累计
Sheets("Sheet1").Cells(g, 15) = WorksheetFunction.Round(WorksheetFunction.SumIfs(sumRange, criteriaRange, Cells(g, 14), criteriaRange_date, "=" & Cells(g, 13)), 2)
Next g
End Sub
运行后结果:

边栏推荐
- UE4 two ways to obtain player control
- Switch to router technology: OSPF single zone configuration, OSPF multi zone and end zone
- C language -- string function, memory function collection and Simulation Implementation
- 2022河南萌新联赛第(三)场:河南大学 J - 神奇数字
- 一个sql server查询截止某个日期最新的记录
- 阿里云工业视觉智能工程师ACP认证——备考
- Torch slice maintenance
- There was an unexpected error (type=Method Not Allowed, status=405).记录报错
- 2022 Hangdian multi school DOS card (line segment tree)
- AXI协议(4):AXI通道上的信号
猜你喜欢

UE4 controls the rotation of objects by pressing keys

QT compilation error sorting and remote module Download

嵌入式实操----基于RT1170 FreeRTOS实现CPU使用率统计(二十四)

快恢复二极管工作原理及使用
![[semantic segmentation] 2018-deeplabv3+ ECCV](/img/c9/d1e2d7e63df8db2a7fa2bde31b10f7.png)
[semantic segmentation] 2018-deeplabv3+ ECCV

2022河南萌新联赛第(三)场:河南大学 L - 合成游戏
![[mathematical modeling] analytic hierarchy process (AHP)](/img/20/8ebd951a0e0c46d1967c6c8b078a4a.png)
[mathematical modeling] analytic hierarchy process (AHP)

【云原生 | 17】容器的四种网络模式

Tonight! Stonedb is officially open source. Please check this strategy~

Icml2022 | imitation learning by evaluating the professional knowledge of the presenter
随机推荐
C语言——指针一点通※
[wp][gwctf 2019] boring lottery
Solve the error string value: '\xf0\x9f\x98\xad',... 'for column' commentcontent 'at row 1
「游戏引擎 浅入浅出」4. 着色器
Spark Structured Streaming HelloWorld
科技论文翻译,俄语文档的语法有何特点
UE4 keyboard control switch light
What are the well-known to-do apps at home and abroad
[mathematical modeling] basic knowledge of MATLAB
How to connect tdengine through idea database management tool?
New knowledge in big homework
【语义分割】2018-DeeplabV3+ ECCV
Add and modify the verification logic, and use -validation- to complete the group verification
Leetcode - monotone stack and monotone queue
Is this my vs not connected to the database
Network Security Learning - permission promotion 2
时代潮流-云原生数据库的崛起
Yapi installation
STM32 development | ad7606 parallel multi-channel data acquisition
"Game engine light in light out" 4. shader