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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
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,214,632
Messages
6,120,652
Members
448,975
Latest member
sweeberry

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