Ok, so there's ActiveCell and ActiveSheet...but how 'bout ActiveTable?

Randall00

Board Regular
Joined
Jan 31, 2008
Messages
54
Hi there!

This is about the ever-unfolding mysteries surrounding Tables from Office 2007 in VBA.

The lovely piece of code below does a fine job of removing the Table style from Table1 and converting it to a normal range:

Code:
Sub RemoveTableStyle()
    Dim oSh As Worksheet
    Set oSh = ActiveSheet
    'remove table or list style
    oSh.ListObjects("Table1").Unlist
End Sub

It's the ListObjects("Table1") bit that I'm wondering about. Every piece of code related to tables that I can find seems to refer to them in this way, but the question is:

Is there a way to refer to the active table?

i.e.
Rich (BB code):
Sub RemoveTableStyle()
    Dim oSh As Worksheet
    Set oSh = ActiveSheet
    'remove table or list style
    ActiveSheet.ActiveTable??.Unlist
End Sub

I imagine this comes back to declaring variables in way that I don't quite understand--a point in the right direction would be appreciated, thanks! :cool:
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I'd best bump this and see if anyone's got any ideas. I don't think it's all that stupid a question. :confused:
 
Upvote 0
In order for a table to be active, a cell inside of that table must be activated. Select a cell within the table and try this:
ActiveCell.ListObject.Range.Select
(This should select your table or whatever ListObject your active cell is a part of)

ActiveCell.ListObject.Unlist
(This Should remove only the table but not the cell values)

I was having the same issue just a second ago and that is what I came up with.
Hope it helps :)
 
Upvote 0

Forum statistics

Threads
1,215,730
Messages
6,126,527
Members
449,316
Latest member
sravya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top