![](/img/trans.png)
[英]Error in my VBA Selection.SpecialCells(xlCellTypeConstants, 1) cell.Value = cell.Text
[英]Selection.SpecialCells() method returns unexpected range (Excel VBA)
当我 select 三个单元格的范围说 B3:B5 时,该方法按预期运行并显示三个消息,分别为“3”、“4”和“5”。
Sub visTest()
Dim c As Range
For Each c In Selection.SpecialCells(xlCellTypeVisible)
MsgBox c.row
Next c
End Sub
问题是当我 select 只有一个单元格时: Selection.SpecialCells(xlCellTypeVisible)
返回工作表上的所有可见单元格并从单元格 A1 开始。
如何让它只返回一个选定单元格中的一个可见单元格? 为什么会出现问题?
谢谢!
这将执行正确的限制:
Sub visTest()
Dim c As Range
For Each c In Intersect(Selection, Selection.SpecialCells(xlCellTypeVisible))
MsgBox c.Row
Next c
End Sub
为了消除使用“ specialCells”时范围错误的问题,只需将这一行添加到代码中
If Selection.Cells.Count > 1 Then Selection.SpecialCells(xlCellTypeVisible).Select End If
只有当实际销售的区域包含多个单元格时,excell才会使用这种方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.