Hi VBA Noob,
I tried that but doesn't seem to work...
If I add that If Statement then it works properly when their are two sheets, but not when there are more than two...
I am not sure why?
Thanks again!
Hi VBA Noob,
I tried that but doesn't seem to work...
If I add that If Statement then it works properly when their are two sheets, but not when there are more than two...
I am not sure why?
Thanks again!
Try
VBA Noob![]()
Sub RenameTemplateSheet() Dim numOfShts As Integer numOfShts = 0 If Sheets.Count > 2 Then For i = 3 To Worksheets.Count If IsEmpty(Worksheets(i).Range("A6")) Then numOfShts = numOfShts + 1 End If Next i Dim sheetsArray() As Variant ReDim sheetsArray(numOfShts - 1) j = 0 For iSheet = 3 To Worksheets.Count If IsEmpty(Worksheets(iSheet).Range("A6")) Then sheetsArray(j) = Worksheets(iSheet).Name j = j + 1 End If Next iSheet Worksheets(sheetsArray).Delete Worksheets(1).Range("C9:AI50,AK9:AN50").ClearContents Worksheets(2).Name = "TEMPLATE" Worksheets(2).Range("A1") = "TEMPLATE" Else MsgBox "There are only " & Sheets.Count & " sheets in workbook" End If End Sub
_________________________________________
![]()
![]()
Credo Elvem ipsum etian vivere
_________________________________________
A message for cross posters
Please remember to wrap code.
Forum Rules
Please add to your signature if you found this link helpful. Excel links !!!
Good evening Excel Newbie05
It seems to be because of the line :
If Worksheets.Count is less than three, then it cannot count backwards unless you qualify the statement with a Step -1 instruction. The loop will do nothing.![]()
For i = 3 To Worksheets.Count
As you variables (j in particular) are quantified within the loop, they are set to 0 outside the loop, Excel is not picking up and deleting the sheets it should.
HTH
DominicB
Please familiarise yourself with the rules before posting. You can find them here.
To turn off the sheet delete message add this at the start
and this at the end![]()
Application.DisplayAlerts = False
VBA Noob![]()
Application.DisplayAlerts = True
Thank you VBA Noob! This worked Wonders!!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks