Selection.SpecialCells()方法返回意外范围(Excel VBA) [英] Selection.SpecialCells() method returns unexpected range (Excel VBA)
本文介绍了Selection.SpecialCells()方法返回意外范围(Excel VBA)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我选择三个单元格的范围,例如B3:B5时,该方法将按预期方式工作并显示带有"3","4"和"5"的三个消息.
When I select a range of three cells say B3:B5, the method acts as expected and displays three messages with "3", "4" and "5".
Sub visTest()
Dim c As Range
For Each c In Selection.SpecialCells(xlCellTypeVisible)
MsgBox c.row
Next c
End Sub
问题是当我仅选择一个单元格时: Selection.SpecialCells(xlCellTypeVisible)
返回工作表上所有可见的单元格,并从单元格A1开始.
The problem is when I select only one cell:
the Selection.SpecialCells(xlCellTypeVisible)
returns ALL visible cells on the worksheet and starts from the cell A1.
如何使它只返回一个选定单元格中的一个可见单元格?为什么会出现问题?
How do I make it return only one visible cell within the one selected cell? Why the problem occurs?
谢谢!
推荐答案
这将执行正确的限制:
Sub visTest()
Dim c As Range
For Each c In Intersect(Selection, Selection.SpecialCells(xlCellTypeVisible))
MsgBox c.Row
Next c
End Sub
这篇关于Selection.SpecialCells()方法返回意外范围(Excel VBA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文