+ Reply to Thread
Results 1 to 7 of 7

How to delete databodyrange in listobject?

  1. #1
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,841

    How to delete databodyrange in listobject?

    Why does this
    Please Login or Register  to view this content.
    work perfect in the immediate window
    while this simple code does not work. Yes there are listobjects on the activesheet.
    Please Login or Register  to view this content.
    <----- If you were helped by my posts you can say "Thank you" by clicking the star symbol down to the left

    If the problem is solved, finish of the thread by clicking SOLVED under Thread Tools
    I don't wish to leave you with no answer, yet I sometimes miss posts. If you feel I forgot you, remind me with a PM or just bump the thread.

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

    Re: How to delete databodyrange in listobject?

    What error do you get?

    Can you actually delete the ranges manually?
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,841

    Re: How to delete databodyrange in listobject?

    Deleting the ranges manually is a feature in excel so that works of course. Or what do you mean by manually? Like I mentioned it works fine in the immediate window.

    Nevermind, I solved it I think. The "On Error Resume Next" statement was needed in case the databodyrange already was deleted, got an error if I tried to do it twice. Not the most proper way to do it but for this little snippet it works ok.
    I tried to use an if statement to check the size of the databodyrange to determine if I could delete it but that causes another error.

    I am using the name of the sheet (not the name on the tab, the object name) instead of activesheet for a more robust solution.

    Please Login or Register  to view this content.

    Edit: I just saw this post, written by a certain mr Pope. It answers my question.
    http://www.excelforum.com/excel-prog...=1#post3288648
    Last edited by Jacc; 08-11-2013 at 08:15 AM.

  4. #4
    Valued Forum Contributor
    Join Date
    05-20-2013
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2013
    Posts
    941

    Re: How to delete databodyrange in listobject?

    Use either...

    Please Login or Register  to view this content.
    ...or...

    Please Login or Register  to view this content.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to delete databodyrange in listobject?

    Jacc

    Instead of sticking a On Error Resume Next in the code, check if the DataBodyRange is nothing.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  6. #6
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,841

    Re: How to delete databodyrange in listobject?

    Sorry jhren but these only work once. If I run it a second time I get error message. The reason apparently is that the object becomes nothing after being deleted, as Norie is pointing out. In my last post there was a link to an old post were Andy comes with the same answer.
    Thanks for contributing, it works like a charm now.

  7. #7
    Valued Forum Contributor
    Join Date
    05-20-2013
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2013
    Posts
    941

    Re: How to delete databodyrange in listobject?

    @Jacc

    I was in Reply mode when you made your last post (#3)... so didn't see it until after I posted, and Norie brought up the issue almost immediately thereafter... so I felt no need to amend.

    As far as my post goes, your initial post gave no indication of any Table being empty (single blank row)... which is why you get an error when you run the second time. But as you have discovered, including the possibility in the code proves wise

    Glad you got it sorted..!!!
    Last edited by jhren; 08-11-2013 at 12:56 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] ListObject DataBodyRange Returns Object Variable Not Set Error
    By goss in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-20-2013, 01:51 PM
  2. Use of ListObject
    By j_Southern in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-04-2013, 03:29 PM
  3. ListObject
    By costadina in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-24-2009, 08:20 PM
  4. ListObject Name ?
    By rvExcelNewTip in forum Excel General
    Replies: 10
    Last Post: 01-22-2007, 11:29 AM
  5. Count nullstrings in pivot table (databodyrange)
    By jonasmj in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-27-2005, 10:06 AM

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