gpt4 book ai didi

vba - 如何通过VBA仅循环遍历Excel工作表中列中的非空单元格?

转载 作者:行者123 更新时间:2023-12-04 21:08:27 26 4
gpt4 key购买 nike

根据this website .

我认为这应该有效:

Dim cell As Range
For Each cell In xxxSheet.Range("B:B").SpecialCells(xlCellTypeFormulas, xlNumbers)
'Do sth.
Next

这是行不通的。有什么遗漏吗?

最佳答案

这应该是有效的解决方案:

For Each cell In xxxSheet.Range("B:B")
If Not IsEmpty(cell) Then
'do sth
End If
Next
此外,如果您想循环直到最后一个填充单元格,您可以使用以下内容:
xxxSheet.Range("B1:B" & Cells(Rows.Count, 2).End(xlUp).Row)
代替
xxxSheet.Range("B:B")

关于vba - 如何通过VBA仅循环遍历Excel工作表中列中的非空单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45670505/

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