VBA: get name of the 3rd worksheet and then split it

dl7631

Board Regular
Joined
Mar 6, 2009
Messages
114
Hello!

I have several worksheets on one file. The third worksheet is called <letter P + some number>, e.g. 'P27' or 'P138'. The first two sheets have very different names.

What would be the VBA code to:

1. Add a new THIRD worksheet - i.e., right before the current third sheet
2. Name it <P + number that is the number of the current 3rd sheet + 1>, e.g., if the current 3rd sheet is 'P27', then the new 3rd sheet should be called 'P28'.

Thank you so much!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
How about
Code:
Sub AddSht()

   Dim ShtNme As String
   With Sheets(3)
      ShtNme = Left(.Name, 1) & Right(.Name, Len(.Name) - 1) + 1
   End With
   Sheets.Add(Sheets(3)).Name = ShtNme
   
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,216,076
Messages
6,128,669
Members
449,463
Latest member
Jojomen56

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