excel - 如何计算 VBA 中非空白的单元格?
问题描述
我遇到了一个错误,我无法让我的 CountIf 工作。在我的“2020 Master RMA”表中,我的 A 列中的日期格式为 m/d/yyyy。我想要发生的情况如下:检查 A 列。如果 A 列符合 1 月标准(即,如果 monthNum = 1),则直接转到 O 列,查看该单元格中是否还有日期。如果该单元格中有日期,则将该日期与该列 O 中日期的其余非空白单元格一起计算。
我希望 O 列的结果进入另一个名为“March Presentations”的表格中的单元格。结果将进入单元格 AE49。
我应该在单元格 AE49 中得到 3 的值,但我只得到 1 的值,在看了几个小时后我仍然无法弄清楚为什么。
Sheets("2020 Master RMA's").Select
lastRow = ActiveSheet.UsedRange.Rows.Count
For row = 2 To lastRow
monthNum = Month(Worksheets("2020 Master RMA's").Range("A" & row).Value)
If monthNum = 1 Then
January = January + 1
JanuaryQE = Application.WorksheetFunction.CountIfs(Worksheets("2020 Master RMA's").Range("O" & row), "<>""")
Next
Sheets("March Presentation").Select
Worksheets("March Presentation").Range("AD49").Value = January
Worksheets("March Presentation").Range("AE49").Value = JanuaryQE
解决方案
With Worksheets("2020 Master RMA's")
lastRow = .Range("A" & .Rows.Count).End(xlUp).Row
For Row = 2 To lastRow
monthNum = Month(.Range("A" & Row).Value)
If monthNum = 1 Then
January = January + 1
januaryqe = januaryqe + IIf(.Range("O" & Row) <> "", 1, 0)
End If
Next
End With
With Worksheets("March Presentation")
.Range("AD49").Value = January
.Range("AE49").Value = januaryqe
End With
推荐阅读
- docker - Docker compose:如何定义指向容器内某个文件而不是物理服务器的 env_file
- python - 如何有效地删除 .xls 文件中标头上方的垃圾
- javascript - 在 Vue.js 的对象字段上使用 v-for 时如何打印索引?
- android - 自定义模型 [MLKit] - FirebaseMLException:执行 Firebase ML 任务时发生内部错误
- google-cloud-firestore - 如何使用 REST API 的结构化查询查询 Firestore 中的对象数组?
- reactjs - ReactJS自定义光标效果:用户滚动时光标不起作用
- java - 如何在 Java 中将日期类型 Angular 转换为 LocalDate
- powershell - 如何在没有时间的情况下将时间戳 - 日期时间转换为 dd-MM-yyy
- python - 如果我将一个包导入python,我是否还必须分别重要它的模块?
- flutter - Dart:带有特殊字符的排序列表