Solved

VBA - Can't Unlist Table in Excel 2010

Posted on 2015-02-19
10
453 Views
Last Modified: 2016-02-10
Hi Experts,

I'm using ActiveSheet.ListObjects("myTABLE").Unlist to delete a Table but it gives me a Run-time error '9',  "Subscript out of range" error (even though I can visually see the Table name and location in the Name Manager dialog) but if I then try to add the same "myTable" Table with an .Add parameter, I get another Run-time error '1004' error saying "A table cannot overlap another table" (and there are no other Tables that overlap this Table's Rows/Columns).  

In the attached file, the calling sub that is causing the problem is "View_Room_Requirements_V1" and the actual Table name I'm trying to delete if it exists (and then subsequently add back) is: "TABLE_Room_Requirements".  I got around the original error by only trying to Unlist it IF it exists, but the subsequent Add still doesn't work because I can't delete the Table.

Hope this is clear.

Jeff
Master-Database-v-5.9--Re-Built----EE-Ex
0
Comment
Question by:jeffreywsmith
  • 5
  • 5
10 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40620112
You uploaded a file that has no code.
0
 
LVL 2

Author Comment

by:jeffreywsmith
ID: 40620158
Not sure what happened there, Martin, but I'll attach it again here.

Jeff
Master-Database-v-5.9--Re-Built----EE-Ex
0
 
LVL 2

Author Comment

by:jeffreywsmith
ID: 40620175
Huh. That one seems to have problems, too.  I notice the file name was changed from what I named it, too.  I will attach it zipped this time ...  Well, EE gives me an error when I try to upload the zipped version: "The archive could not be scanned: Stream closed".  Not sure what to do next ...

Jeff
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40620198
The table name isn't "TABLE_Room_Requirements" it's "TABLE_Room Requirements". No second underscore.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40620203
BTW I believe the problem with us downloading the file is that you didn't include a valid Excel file extension.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Comment

by:jeffreywsmith
ID: 40620422
Martin,

I'm not seeing where "TABLE_Room Requirements" with no second underscore is used.  The Range name uses both underscores and so do all instances of this Table in my code.  Can you advise where you are seeing this?

Also, I did include both the .xlsm and .zip extensions on the files I attempted to upload ... so can only assume a hiccup in the EE system ...
0
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40620457
If you add this code to module1 and run it

Sub ListListobjects()
Dim lngListObj As Long

With Sheets("2015 PCA FALL GRUPPENEINTEILUNG")
    For lngListObj = 1 To .ListObjects.Count
        Debug.Print "Listobject " & lngListObj & " is named " & .ListObjects(lngListObj).Name
    Next
End With
End Sub

Open in new window


This will be the output in the Immediate Window (Ctrl+g in the VBE)
No second underscore
0
 
LVL 2

Author Comment

by:jeffreywsmith
ID: 40620999
Well, that was strange.  Because I was able to see the Table named WITH the 2nd underscore in Name Manager.  But I did try unlisting the Table name withOUT the 2nd underscore in it, and it did delete.  

Thanks for the help with that, Martin.  Do you have any idea what could cause this and is it suggesting corruption in the file?

If so, I'd appreciate any suggestions on how to recover from same.

Jeff
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40621268
My guess is that it's some type of corruption because I don't believe that Excel normally allows a space in either a Table Name or in a Named Range. You might want to ask a new question and see if anyone has a solid explanation for the situation. If you do that could you please post the URL here because I'd be interested in following the discussion.

In any case you're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0
 
LVL 2

Author Comment

by:jeffreywsmith
ID: 40621296
Thanks, Marty.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now