我遇到了一个问题,其中 CellIsInVisibleRange
函数选择它不应该选择的单元格。
循环的代码如下:
wCount = 0
loopCount = 0
For Each wCell In wRange
loopCount = loopCount + 1
If CellIsInVisibleRange(wCell) Then
MsgBox ("HERE IT BE")
wCount = wCount + 1
"codey-code"
End If
Next
对我来说失败的功能是:
Function CellIsInVisibleRange(cell As Range)
CellIsInVisibleRange = Not Intersect(ActiveWindow.VisibleRange, cell) Is Nothing
End Function
发生的事情是,我有一个可见的行范围是 1、64、65、66。这个循环接受 应该在第 45 行可见 wCell。
我正在看这张纸,那一行绝对是不可见的。
你看到这个功能有什么问题吗?
谢谢。
编辑:
@KekuSemau
谢谢回复。该代码运行良好,但我想知道是否有更有效的方法来执行此操作。行
wCell.SpecialCells(xlCellTypeVisible)
返回“类型不匹配”错误,但我觉得这样的事情会更快。我想我应该表明我也声明了我正在寻找的范围。Set wRange = Range("$" & nameColumnLetter & "$1:$" & nameColumnLetter & "$" & lastRow)
wCount = 0
loopCount = 0
For Each wCell In wRange
loopCount = loopCount + 1
'If CellIsInVisibleRange(wCell) Then
If wCell.SpecialCells(xlCellTypeVisible) Then
code
code
code
End If
Next
我在这里接近更快的方法吗?
再次感谢。
最佳答案
在我们开始讨论之前,我的工作正在进行中的回答,这是我将如何修改您的代码:
Set wRange = Range("$" & nameColumnLetter & "$1:$" & nameColumnLetter & "$" & lastRow)
wCount = 0
'counts blanks and non-blanks, changed from original based on my guess of what you want
loopCount = wRange.Count
Set wRange2 = wRange.SpecialCells(xlCellTypeVisible)
For Each wCell In wRange2
code
code
code
Next wCell
关于VBA VisibleCell 不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31010675/