Copy a Tab and Rename it Based on the First Three Letters of Another Tab

OilEconomist

Board Regular
Joined
Dec 26, 2016
Messages
226
Office Version
  1. 2019
Platform
  1. Windows
Thanks in advance for any suggestions and I will post feedback as soon as practical.

I would like to copy a template named "TEM.CAT.PHD" and place it before "END.PHD.CFP." I would like to rename the template based on the first three letters of another tab and some additional characters. The tab is located after "START.DTA.PHD". In this case it is "TNM.ALL.PHD".

The following are some examples. So basically if the tab name after START.DTA.PHD is:
  • "TNM.ALL.PHD", TEM.CAT.PHD will be copied and placed before "END.PHD.CFP" and renamed "TNM.TOT.CFP."
  • "PAS.ALL.PHD", TEM.CAT.PHD will be copied and placed before "END.PHD.CFP" and renamed "PAS.TOT.CFP."
  • "EAG.ALL.PHD", TEM.CAT.PHD will be copied and placed before "END.PHD.CFP" and renamed "EAG.TOT.CFP."

The following is my code thus far, but I would like to make it dynamic.

Code:
Sub Test()
    
Application.ScreenUpdating = False


'Making the Total Tab
    'Copying the Template
        Worksheets("TEM.CAT.PHD").Copy Before:=Worksheets("END.PHD.CFP")
        On Error Resume Next
        ActiveSheet.Name = "TNM.TOT.CFP"


End Sub
 

Some videos you may like

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,794
Office Version
  1. 365
Platform
  1. Windows
How about
Code:
Sub OilEconomist()
   Sheets("TEM.CAT.PHD").Copy Sheets("END.PHD.CFP")
   ActiveSheet.Name = Left(Sheets(Sheets("START.DTA.PHD").Index + 1).Name, 3) & ".TOT.CFP"
End Sub
 

OilEconomist

Board Regular
Joined
Dec 26, 2016
Messages
226
Office Version
  1. 2019
Platform
  1. Windows
It worked perfectly!

Thank you so much Fluff! You've been a tremendous help!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,794
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,128,132
Messages
5,628,891
Members
416,349
Latest member
salmanb74

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
Top