Rename sheet if there or exit if new sheet is not there

kentster

New Member
Joined
Nov 22, 2016
Messages
28
Hi - I have been trying all day to find and piece together code. I suck. That said, here is my problem. Using Excel 2013, I am wanting to check and see if Sheet 2 exists. If it does, then rename it. Then check to see if Sheet 3 exists. If it does then name it. If Sheet 4 does NOT exist, EXIT the macro. Example code I have below works until there is no Sheet 4...for obvious reason it is looking for a command that will work in the absence of Sheet 4.

There has to be a loop or something to help decide for each sheet....I just cannot figure it out (I suck)

THANKs SO UMCH

'Rename sheets
Sheets(2).Select
Sheets(2).Name = "Deal 1"
Sheets(2).Tab.ColorIndex = 6
Sheets(3).Select
Sheets(3).Name = "Deal 2"
Sheets(3).Tab.ColorIndex = 6
Sheets(4).Select
Sheets(4).Name = "Deal 3"
Sheets(4).Tab.ColorIndex = 6
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Osvaldo Palmeiro

Well-known Member
Joined
Feb 24, 2009
Messages
727
Office Version
  1. 365
Platform
  1. Windows
Hi.
See if this could help you.
Code:
Sub RenameSheets()
 Dim i As Long
  For i = 2 To Sheets.Count
   With Sheets(i)
    .Name = "Deal " & i - 1
    .Tab.ColorIndex = 6
   End With
  Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,191,592
Messages
5,987,524
Members
440,099
Latest member
wai2kit

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
Top