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

OilEconomist

Active Member
Joined
Dec 26, 2016
Messages
439
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
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
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
 
Upvote 0
It worked perfectly!

Thank you so much Fluff! You've been a tremendous help!
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,119
Members
452,381
Latest member
Nova88

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