excel - 如何使用CountA?
问题描述
我必须在我的宏中添加一条规则,检查 Sheet1 中 A1:Z1 范围内是否有空白单元格。如果是,它会运行进一步的代码。如果不是,它将显示 MsgBox 并停止宏。我写
If WorksheetFunction.CountA(Worksheets("Sheet1").Range("A1:Z1")) Then
MsgBox"ERROR"
Else
rest of my code
End If
不幸的是,即使是 A1:Z1 中的那些单元格也是空白的,我看到 MsgBox
请你帮助我好吗?
解决方案
我喜欢跳过工作表函数并做纯 VBA。
'set worksheet
dim ws as worksheet
set ws = worksheets("Sheet1")
'init counter
dim empty as integer
empty = 0
'loop cells
for x = 1 to 26
'check row 1 columns 1 to 26
if trim(ws.cells(1, x)) = "" then
empty = empty + 1
end if
next x
'check empty
if empty > 0 then
'extra code
Else
msgbox "no empty found"
end if
推荐阅读
- node.js - Mongodb检查字符串数组中的任何字符串是否存在另一个字符串
- python - Python:如何从包含列表作为值的字典列表中制作 DataFrame
- r - 在R中为年龄范围创建年龄分层表
- javascript - 如何在javascript中按日期名称对数组进行排序?
- asp.net-core - AuditIgnore 对某些功能
- python - 如何将 CUDA 与 vaex(一个 Python 库)一起使用
- c++ - 将 char 向量转换为 size_t 的 C++ 安全方法
- eclipse-hono - 如何在部署在 K8s 集群上的 Eclipse Hono 中进行服务配置?
- typescript - 根据 serenity-platform 中的条件设置必填/不需要的字段
- blockchain - 使用 ipfs 和区块链的文件搜索和实现