Adding Letters to Existing Tab names VBA

dstrickland91

New Member
Joined
Jun 12, 2015
Messages
19
I make a workbook close to everyday with 26 sheets inside of it. Each sheet is named with a number. Im trying to find a piece of code that will insert a letter in backwards alphabetical order in front of each sheet name. For example my tab names are:

45
54
78
65
13
35
75
14
88

After the code runs, id like this to be the result.

Z45
Y54
X78
W65
V13
U35
T75
S14
R88

The numbers are different everyday so the code has to only insert the letter into the tabname. I used kutools addin and it was doing the trick, but A: it was slightly buggy, B: I didnt want to pay the software cost for that one feature. Id much rather have the piece of code that I can add in to work with my other modules.

Is this possible?
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Try this on a copy of your workbook.
Code:
Sub AddTabLetter()
Dim sht As Worksheet, ct As Long
ct = 90
Application.ScreenUpdating = False
For Each sht In ActiveWorkbook.Sheets
    If sht.Name Like "#*" Then
        sht.Name = Chr(ct) & sht.Name
        ct = ct - 1
        If ct < 65 Then Exit Sub
    End If
Next sht
Application.ScreenUpdating = True
End Sub
 
Upvote 0
This block of code should do that:
Code:
    Dim i As Integer
    For i = 1 To Sheets.Count
        Sheets(i).Name = Chr(91 - i) & Sheets(i).Name
    Next i

Edit: Didn't see JoeMo's reply. He has got a few extra checks built in to his.
 
Upvote 0
Wow, thanks for the fast response. This works perfect. I there anyway this can be edited on the odd occasion I dont have 26 sheets? So say if I have only 25 it would start by inserting y first instead of z? From time to time The file may have an odd number of sheets(never exceeding 26). Basically have it start with A on the last sheet then move forward in that order?

Did I explain this right to where it makes sense?
 
Last edited:
Upvote 0
Wow, thanks for the fast response. This works perfect. I there anyway this can be edited on the odd occasion I dont have 26 sheets? So say if I have only 25 it would start by inserting y first instead of z? From time to time The file may have an odd number of sheets(never exceeding 26). Basically have it start with A on the last sheet then move forward in that order?

Did I explain this right to where it makes sense?
Which fast response you would like modified are you referring to?
 
Upvote 0
Here is mine. with update:
Code:
    Dim i As Long
    Dim Counter As Long
    For i = Sheets.Count To 1 Step -1
        Counter = Counter + 1
        Sheets(i).Name = Chr(64 + Counter) & Sheets(i).Name
    Next i
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,580
Members
449,039
Latest member
Arbind kumar

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