rename sheets and increment continuously for character @

Hasson

Active Member
Joined
Apr 8, 2021
Messages
390
Office Version
  1. 2016
Platform
  1. Windows
Hello
I search for macro to rename any sheets name contain "@" and increment numbers
so the sheets names could be
file@1-1-2023
MNTYVB@1-2-2023
result should be
MT1
MT2
and if I add new sheets like this
asetubn67@1-1-2023
xadfg@1-2-2023
then will increment like this
MT3
MT4
so the final result will be
MT1
MT2
MT3
MT4
and so on when add new sheets contain @ should rename MT and increment numbers.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Thanks for posting on the forum.


Please try the following macro:
VBA Code:
Sub Rename_Sheets()
  Dim sh As Worksheet
  Dim sName As String
  Dim nMax As Long, num As Long
  
  sName = "MT"
  
  For Each sh In Sheets
    If Left(sh.Name, Len(sName)) = sName Then
      num = Mid(sh.Name, 3)
      If num > nMax Then
        nMax = num
      End If
    End If
  Next
  
  nMax = nMax + 1
  
  For Each sh In Sheets
    If InStr(1, sh.Name, "@") > 0 Then
      sh.Name = sName & nMax
      nMax = nMax + 1
    End If
  Next
End Sub

Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
 
Upvote 1
Solution

Forum statistics

Threads
1,214,965
Messages
6,122,496
Members
449,089
Latest member
Raviguru

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