本文介绍了确定ActiveCell是否在特定表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Excel 2013中的VBA确定ActiveCell是否不仅在任何表中,而且还在特定表中.

I am trying to determine by VBA in Excel 2013 if the ActiveCell is not just in any table, but in a specific table.

下面是按原样编写的代码,但仅检测到ActiveCell在任何表中.注释掉的行是我要查找的行,但是显然行不通.

Below is the code as is, but only detects ActiveCell being in any table. The commented out line is what I'm looking for, but obviously it doesn't work.


    ...
    Set rng = Intersect(.EntireRow, ActiveCell.ListObject.DataBodyRange)
    'Set rng = Intersect(.EntireRow, ActiveCell.ListObjects("myTable").DataBodyRange)
    On Error GoTo 0
        If rng Is Nothing Then
            MsgBox "Please select the cell of a row within the consensus input table.", vbCritical, "Delete Evaluator"
        Else
    ...

对此有什么正确语法的建议吗?

Any suggestions on the right syntax for this?

谢谢!

推荐答案

要测试 ActiveCell 是否在 Table1 的正文中:

To test if ActiveCell is in the body of Table1:

Sub qwerty()

   If Intersect(ActiveCell, ActiveSheet.ListObjects("Table1").DataBodyRange) Is Nothing Then
      MsgBox "activecell not in Table1"
   Else
      MsgBox "activecell in Table1"
   End If

End Sub

这篇关于确定ActiveCell是否在特定表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 01:20