Changing a sheet name in a macro to increase in number

samb94

New Member
Joined
Jun 6, 2019
Messages
1
I'm super new to VBA, so I'll try to explain thoroughly:
I have a workbook where I enter data for a specific person in each tab. There's also a master tab that rolls up this data into averages.
In order to add a new tab, I copy the tab, clear out the data, then I copy the row of formulas and do a find and replace to change the sheet name.
I recorded a macro to do all this for me, but the problem is I don't want the macro to rename each sheet "Instructor 7" each time, I need the sheet name to be "Instructor (last sheet #+1)".
Anyone know how to help me?
Here's my VBA code:

Code:
Sub AddNewInst()'
' AddNewInst Macro
' Adds new sheet and creates a new row in Master
'


'
    Sheets("Instructor 1").Select
    Sheets("Instructor 1").Copy Before:=Sheets(1)
    Sheets("Instructor 1 (2)").Select
    Sheets("Instructor 1 (2)").Name = "Instructor 7"
    Range("B3:O30").Select
    Selection.ClearContents
        Range("B1").Select
    Selection.ClearContents
        Sheets("Master").Select
    Range("A3:AB3").Select
    Selection.Copy
    Range("A9").Select
    ActiveSheet.Paste
    Selection.Replace What:="Instructor 1", Replacement:="Instructor 7", _
        LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:= _
        False, ReplaceFormat:=False
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Change this:
Sheets("Instructor 1 (2)").Select
Sheets("Instructor 1 (2)").Name = "Instructor 7"

to this:
Activesheet.Name = "Instructor " & Sheets.Count
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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