Help VBA code for adding new name + existing name in Tabs/Sheets

usui

Board Regular
Joined
Apr 20, 2020
Messages
55
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
Hi Guys,

Need help here on adding new name + existing name in tabs/sheets. I am looking for a piece of code that can help me with my work.
I want to add new set of numbers on the existing tabs.

for example project ID is 2214 : (this are may tab names)
143
188
122
11
901

After the code runs i would like it to be like this.

2214-143
2214-188
2214-122
2214-11
2214-901

please help me, if this is even possible. Thank you so much in advance
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try this:
VBA Code:
Sub Modify_Sheet_Names()
'Modified 4/20/2020 2:58:53 AM EST
Application.ScreenUpdating = False
Dim i As Long
For i = 1 To Sheets.Count
Sheets(i).Name = "2214-" & Sheets(i).Name
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try this:
VBA Code:
Sub Modify_Sheet_Names()
'Modified 4/20/2020 2:58:53 AM EST
Application.ScreenUpdating = False
Dim i As Long
For i = 1 To Sheets.Count
Sheets(i).Name = "2214-" & Sheets(i).Name
Next
Application.ScreenUpdating = True
End Sub

OMG This hits the spot, thank you so much. Is there a way that it would be easy to change the project ID by not editing the VBA?

Like maybe a pop up box to enter the desire project ID instead?
 
Upvote 0
Try this:
VBA Code:
Sub Modify_Sheet_Names()
'Modified 4/20/2020 3:39:18 AM EST
On Error GoTo M
Application.ScreenUpdating = False
Dim i As Long
Dim Project As String
Project = InputBox("Enter Project Number")
For i = 1 To Sheets.Count
Sheets(i).Name = Project & "-" & Sheets(i).Name
Next
Application.ScreenUpdating = True
Exit Sub
M:
MsgBox "You may have tried to make a improper sheet name"
End Sub
 
Upvote 0
Try this:
VBA Code:
Sub Modify_Sheet_Names()
'Modified 4/20/2020 3:39:18 AM EST
On Error GoTo M
Application.ScreenUpdating = False
Dim i As Long
Dim Project As String
Project = InputBox("Enter Project Number")
For i = 1 To Sheets.Count
Sheets(i).Name = Project & "-" & Sheets(i).Name
Next
Application.ScreenUpdating = True
Exit Sub
M:
MsgBox "You may have tried to make a improper sheet name"
End Sub


OMG you are may life saver, thank you so much for this big help.
 
Upvote 0
Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.

Sure, i will be around because I'm dealing with excel for my work. I will post a new thread later for consolidating multiple workbooks to one.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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