Link to home
Start Free TrialLog in
Avatar of route217
route217Flag for United Kingdom of Great Britain and Northern Ireland

asked on

VBA Code to change worksheet tab name.

Hi Experts.

The tab name end part is different each month as it relates to the day and month the download was done.

So In Sept 20
Tab worksheet tab name would be Imap Product 20-09 in Oct this would Imap Product 20-10.

I want to dynamically change this tab name to IMAP Products each month (ignore date element) in total I have 30 tab names to change..

Avatar of HainKurt
HainKurt
Flag of Canada image

can you post a sample excel
you cannot give same names to sheets...

Avatar of route217

ASKER

Hang fire ill.post and excel workbook..might be a while
Avatar of Flyster
These two lines will change the tab name to the format you want:
tName = "Imap Product " & Format(DateValue(Now), "yy-mm")
ActiveSheet.Name = tName

Open in new window

It uses the Now function so if you run it in November it will name the tab "Imap Product 20-11". If you need it to change to reflect the value of a certain cell, such as A1, then change DateValue(Now) to DateValue(Range("A1").Value 

Paul
@Flyster

he says "I have 30 tab names to change..."
so, it is not clear how to change all, they should be unique names...
ASKER CERTIFIED SOLUTION
Avatar of Flyster
Flyster
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@Flyster 
This code will loop through your workbook and change all the tab names 
so you assume, we have dates stored somewhere...
and use it to rename all tabs to "Imap Product YY-MM"

I doubt so...
waiting for excel he will post...
The day and month are needed.
From where are those data pulled from ?
 Hi Experts

I am going to provide a full mapping shortly from too.. day and month are not required. That part has to be removed 
So, each worksheet should be named "IMAP Products" ?
Not doable, Excel do not allow duplicate names for worksheets.