【问题标题】:Error 424 : Object required _ setting Table as a range错误 424:需要对象 _ 将表设置为范围
【发布时间】:2019-09-19 11:46:12
【问题描述】:

以下代码用于表格中选定行的条件格式。
我尝试用表名引用替换与表相关的范围,以便在添加新数据时自动更改范围。 但是当我尝试这样做时,它显示以下消息:

代码中突出显示的行是红色的行,如下所示。
任何帮助将不胜感激。

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim tbl As ListObject
Set tbl = ActiveSheet.ListObjects("Table1")   
[COLOR="#FF0000"]If Not Intersect(Target, tbl.DataBodyRange.Select) Is Nothing Then  [/COLOR] 
        Dim Cell As Range
        Range("A4").NumberFormat = "@"
        If Target.Count > 1 And Target.Count < 50 Then
        StopCode
        For Each Cell In Selection
        Range("A4").Value = Range("A4").Value & "(" & Cell.Row - 21 & ")"
        Next Cell
        ResetCode
        Else
        Range("A4").Value = "(" & Target.Row - 21 & ")"
        End If
Else
Range("A4").ClearContents
End If
End Sub

【问题讨论】:

    标签: excel vba tablename


    【解决方案1】:

    尝试以下操作,而不使用 Select...

    If Not Intersect(Target, tbl.DataBodyRange) Is Nothing Then
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-30
      • 2017-12-09
      • 2018-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多