Hi Everyone,
I wrote the function below so it could
1) Clear all contents in sheet 1 range C9:AI50,AK9:AN50
2) Rename worksheet 2 to "TEMPLATE" and cell A1 in worksheet 2 to "TEMPLATE"
3) Delete all other worksheets in the workbook but sheet 1 and 2.
Now Here is my issue, this code works, expect for when I have only 2 worksheets?? Can someone give me some insight on what I may be doing wrong??
Thanks!
Sub RenameTemplateSheet()
Dim numOfShts As Integer
numOfShts = 0
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"
End Sub
Bookmarks