+ Reply to Thread
Results 1 to 3 of 3

ListObject DataBodyRange Returns Object Variable Not Set Error

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-07-2004
    Posts
    314

    ListObject DataBodyRange Returns Object Variable Not Set Error

    Hi all,

    Using Excel 2010.


    I would like to test a DataBodyRange of a ListObject and delete the DataBodyRange if the Rows.count >=1
    My code is returning an error:
    Run-time error '91':
    Object variable or With block block variable not set
    But I do not see a problem wi the code (Below)

    thx
    w

        'Clear previous data
            With ws
                Set tbl = .ListObjects("tblData")
                With tbl
                    If .DataBodyRange.Rows.Count >= 1 Then
                        .DataBodyRange.Delete
                    End If
                End With
            End With
    Kind regards,
    w

    http://dataprose.org

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,444

    Re: ListObject DataBodyRange Returns Object Variable Not Set Error

    The DataBodyRange object is Nothing when the table has no rows, so test for that.

            With ws
                Set tbl = .ListObjects("tblData")
                With tbl
                    If Not .DataBodyRange Is Nothing Then
                        .DataBodyRange.Delete
                    End If
                End With
            End With
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    01-07-2004
    Posts
    314

    Re: ListObject DataBodyRange Returns Object Variable Not Set Error

    Thanks Andy,

    Your code is working perfectly!

    thx
    w

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1