Sub Rename()
Dim ws As Worksheet
Dim sheetExists As Boolean
sheetExists = False
For Each ws In ThisWorkbook.Worksheets
If ws.Name = "Jan" Then
sheetExists = True
ws.Name = "Feb"
Exit For
End If
Next ws
If Not sheetExists Then
MsgBox "Sheet 'Jan' does not exist."
Else
MsgBox "Sheet 'Jan' has been renamed to 'Feb'."
End If
End Sub
Dim X As Variant
On Error Resume Next
X = ActiveWorkbook.Worksheets("Jan").Name
On Error GoTo 0
If IsEmpty(X) Then
ActiveSheet.Name = "Jan"
Else
ActiveSheet.Name = "Feb"
End If
Sub Rename()
Dim LastMonth As String, ThisMonth As String
LastMonth = MonthName(Month(Date) - 1, True)
ThisMonth = MonthName(Month(Date), True)
If Evaluate("ISREF('" & LastMonth & "'!A1)") Then ThisWorkbook.Worksheets(LastMonth).Name = ThisMonth
End Sub
Sub Change_Sheet_Name()
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
If [ISREF(Jan!A1)] Then Sheets("Jan").Name = "Feb": Exit For
Next sh
End Sub
Private Sub CommandButton1_Click()
Dim i As Long
For i = 1 To Sheets.Count
Select Case Sheets(i).Name
Case "Jan": Sheets(i).Name = "Feb"
End Select
Next
End Sub
Hi,There a few different ways. Here is one.
VBA Code:Dim X As Variant On Error Resume Next X = ActiveWorkbook.Worksheets("Jan").Name On Error GoTo 0 If IsEmpty(X) Then ActiveSheet.Name = "Jan" Else ActiveSheet.Name = "Feb" End If