create a new sheet and then rename all other sheets using unique names

INN

Board Regular
Joined
Feb 3, 2021
Messages
118
Office Version
  1. 365
Platform
  1. Windows
Hi
I am trying to create a new sheet and then rename other sheet with unique name, how can I do that? or can i check the names and then when I name a sheet to for example 1, I want excel to search for this name in all sheets and if it is there then either change the name of the new one to something else or change the other one. Thank you very much.
Code:
Sub abcd()
    ' adding sheet then rename the reset
    Worksheets.Add before:=Worksheets(1)
    Dim x As Integer
    Dim y As Integer
    x = Worksheets.Count
    For y = 1 To x
    Worksheets(y).Name = y
    Worksheets(y).Tab.ColorIndex = y + 4
    Next y
End Sub
 
Last edited:

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi INN,

maybe like this

VBA Code:
Sub MrE_1222501_161420B()
' https://www.mrexcel.com/board/threads/create-a-new-sheet-and-then-rename-all-other-sheets-using-unique-names.1222501/
' working in the active workbook
' adding sheet then rename the reset
Dim intIndex As Integer
Dim lngNext As Long

Worksheets.Add before:=Worksheets(1)
lngNext = 1
For intIndex = 1 To Worksheets.Count
  Do While Evaluate("ISREF('" & lngNext & "'!A1)")
    lngNext = lngNext + 1
  Loop
  With Worksheets(intIndex)
    .Name = lngNext
    .Tab.ColorIndex = lngNext + 4
  End With
  lngNext = 1
Next intIndex
End Sub

or maybe
VBA Code:
Sub MrE_1222501_161420B_Vers2()
' https://www.mrexcel.com/board/threads/create-a-new-sheet-and-then-rename-all-other-sheets-using-unique-names.1222501/
' working in the active workbook
' adding sheet then rename the reset
Dim intIndex As Integer

Worksheets.Add before:=Worksheets(1)
For intIndex = 1 To Worksheets.Count
  Do While Evaluate("ISREF('" & intIndex & "'!A1)")
    Worksheets(CStr(intIndex)).Name = intIndex + Worksheets.Count
  Loop
  With Worksheets(intIndex)
    .Name = intIndex
    .Tab.ColorIndex = intIndex + 4
  End With
Next intIndex
End Sub

Ciao,
Holger
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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