Macro - Adapting a Table's name every time the macro runs

Jeeremy7

Board Regular
Joined
May 13, 2020
Messages
110
Office Version
  1. 365
Platform
  1. Windows
Hello everyone,

So every month we export data and this data was always sorted a editited by hand.
I wanted to create a macro to automate it because it's always the same type of modification.
The problem is that we would have 1 tab per month in excel.

When I ran the original macro I created a table and just changed it's layout color.
The problem is that when I ran the same macro in an other tab, I have an error because the "table1" is now "table2".

Is there a way that the macro would not select the table name but the table in the active sheet instead ?

Thanks a lot !
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
If you only have one table per sheet you can use something like
VBA Code:
Sheets("Sheet1").ListObjects(1).TableStyle = "TableStyleMedium7"
 
Upvote 0
Solution
If you only have one table per sheet you can use something like
VBA Code:
Sheets("Sheet1").ListObjects(1).TableStyle = "TableStyleMedium7"
Can I use the activesheet instead or it wouldn't work ?
I would have the same button in each month tab so the sheet would not always be the same name

Thanks !
 
Upvote 0
Now I have the same problem with the part when I insert a slicer. I tried modifying the "Table" by 1 again but not working :/
Does the 1 means "the first table you see" ?
 
Upvote 0
It's the first table in the listobjects collection on that sheet.
 
Upvote 0
Ok the problem is I think when doing a slicer it wrote ActiveWorkbook but when I modify to ActiveSheet it doesn't work
 
Upvote 0
I've never used slicers, so unfortunately cannot help with that.
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

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