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

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
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,217,382
Messages
6,136,240
Members
450,000
Latest member
jgp19

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