gpt4 book ai didi

excel - 连续计数可见空白单元格

转载 作者:行者123 更新时间:2023-12-04 20:16:33 25 4
gpt4 key购买 nike

我有一个数据集,每列中有大量空白字段。在将一些任意过滤器应用于其他列之后,我想计算每列中空白单元格的数量。

我已经让它在 sub 中工作与以下

 Sub whatever()
Dim myrange As Range
Set myrange = Worksheets("Sheet1").Range("a1:a100")
myrange.SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeBlanks).Count
End Sub

但是当我尝试像这样把它放在 UDF 中时
 Function CountBlankVisible(myrange As Range)
CountBlankVisible = myrange.SpecialCells(xlCellTypeVisible).SpecialCells(xlCellTypeBlanks).Count
End Function

无论单元格类型如何,它似乎都在计算范围内的每个单元格。任何想法为什么这会在子系统中工作而不是作为函数?是否可以通过其他方式获得此计数?

最佳答案

Excel UDF 有一些限制(从工作表调用时)。您可以阅读它们 here .

这是工作示例:

Function CountBlankVisible(myrange As Range)
Dim c As Range
For Each c In myrange
If c.RowHeight > 0 And IsEmpty(c.Value) Then _
CountBlankVisible = CountBlankVisible + 1
Next
End Function

关于excel - 连续计数可见空白单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22986032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com