Naming a table in a macro

Christiinin

New Member
Joined
Aug 16, 2017
Messages
2
Hello!

I'm new in the wondrous world of VBA-coding and macros, and could use a few tips on how to proceed :)

My goal is to make a macro to create a new table with my setting preferences, and giving it a unique name.

My problem occurs, when I'm using my recorded macro on another set of data, it wants to give it the same name as the first.

My ideas for solutions:
- Copy a name from a cell ("A1") and pasting it into the name field in the design tab.
- A pop up box during the macro, giving the user the option to type in the name
- An auto generated unique name, every time the macro is run

But I don't yet know how to implement it.

I'm open to other suggestions aswell :D
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
ActiveSheet.ListObjects("Table1").Name = [A1]
ActiveSheet.ListObjects("Table1").Name = InputBox("Name for table:")
ActiveSheet.ListObjects("Table1").Name = Int((99999999 - 10000000 + 1) * Rnd + 10000000)
 
Last edited:
Upvote 0
Thanks! :)

I do have a followup question:


Range("B2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select


ActiveSheet.ListObjects("Table1").Name = InputBox("Name for table:")

Range("Table1[#All]").Select

ActiveSheet.ListObjects("Table1").ShowAutoFilterDropDown = False
ActiveSheet.ListObjects("Table1").ShowTableStyleFirstColumn = True

How do I get it to refer to the newly named table?

Thanks!
Christin
 
Upvote 0
Code:
newname = InputBox("Name for table:")
ActiveSheet.ListObjects("Table1").Name = newname
ActiveSheet.ListObjects(newname).ShowAutoFilterDropDown = False
ActiveSheet.ListObjects(newname).ShowTableStyleFirstColumn = True
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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