Incremental Sheet names

kin1

New Member
Joined
Mar 31, 2011
Messages
37
hello,

can someone help me with a formula that will check for the sheet names and if there's a duplicate, it will increment it by a value of 1?

example.
sheet1
if sheet1 already exsist that it will create a sheet2, and if sheet2 already exsist it will name it sheet3, etc.

thanks,
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Welcome to the baord..

Are ALL the sheets named in this same format..
Sheet1
Sheet2
Sheet3
etc
Sheet21

Or are there other sheetnames mixed in ?

And are they displayed in incrimental order from left to right?

And is it literally Sheet1 Sheet2? or something else but similar?
Post the EXACT sheet names please.
 
Upvote 0
hi,

thanks for responding.

i have a macro that processes a single tab excel file, it renames this tab to attachment. but sometimes the file comes with multiple tabs, and i dont know how to rename duplicates.

i have activesheet.name = "attached", and it processes this file. say when it's done and i go to the next tab. it will try to name it "attached" again since that's how it's coded. i would like the second "attached" file to be attached1 or and so on.

i hope that makes sense.
thanks,
 
Upvote 0
Try something like this

Code:
For i = 1 to Sheets.Count
    On Error Resume Next
    If Sheets("Attached" & i).Name = "Attached" & i Then
        'Do Nothing, sheet exists already
    Else
        Sheets.Add
        ActiveSheet.Name = "Attached" & i
        Exit For
    End If
    On Error Goto 0
Next i
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,738
Members
452,940
Latest member
Lawrenceiow

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