本文介绍了如何确定工作表单元格是否可见/在VBA中显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找到一个单元格是否在屏幕上可见。

I need to find if a cell is visible on the screen.

可见,我不是隐藏的。我专门试图找到一个单元格当前是否显示在活动工作表中,或者如果它不显示,即:已经从可见的活动工作表中滚动。

By visible, I don't mean hidden. I am specifically trying to find if a cell is currently displayed in the active sheet, or if it is not displayed, ie: it has been scrolled off of the visible active sheet.

我已经上网了,只能找到下面的代码,似乎不适合我:

I have looked online, and can only find the following code which doesn't seem to work for me:

Private Sub CommandButton1_Click()
    With Worksheets(1).Cells(10, 10)
        'MsgBox "Value: " & .Value & ", Top: " & .Top & ", Left: " & .Left
        Dim visibleCells As Range
        Set visibleCells = Range("A1").CurrentRegion.SpecialCells(xlCellTypeVisible)
        If Intersect(Worksheets(1).Cells(10, 10), visibleCells) Is Nothing Then
            MsgBox "This cell is not visible."
        End If
    End With
End Sub

提前感谢为您的帮助,

Marwan

推荐答案

这是一个功能你想要什么:

Here's a function that does what you want:

Function CellIsInVisibleRange(cell As Range)
CellIsInVisibleRange = Not Intersect(ActiveWindow.VisibleRange, cell) Is Nothing
End Function

至少我认为它是。我直到现在还没有意识到VisibleRange属性。

At least I think it does. I hadn't been aware of the VisibleRange property until now.

调用如下:

If CellIsInVisibleRange(ActiveSheet.Range("A35")) Then
    MsgBox "Cell is visible"
Else
    MsgBox "Cell isn't visible"
End If

这篇关于如何确定工作表单元格是否可见/在VBA中显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 16:55