Solved

VBA - Can't Unlist Table in Excel 2010

Posted on 2015-02-19
10
522 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 47

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
Increase your protection from Zero Day threats!

Running two Antivirus' is never a good idea.
Taking advantage of Multiple Security layers on the other hand can often save your hide.
See which top notch security software brands have been proven to happily coexist together.
Reduce your chances of becoming a statistic.

 
LVL 47

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 47

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
 
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 47

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 47

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

SuperAntiSpyware Licenses Discounted by 25% !

Exclusive offer to Experts Exchange Members!
Buy SuperAntiSpyware License(s) from us and save 25% on the regular purchase price.
- Includes Full SuperAntiSpyware Vendor Support Entitlements
- Your Subscription does not begin until you activate your license
- Buy for your friends

Question has a verified solution.

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

Suggested Solutions

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

751 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