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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
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,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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