In this code, if the cell value is having some special characters like "/" etc, it showing error.
I need to exclude that error and remove the special character in the particular cell and rename as it is.
Example : B1 cell is having " ABC/ DCF"
While renaming the sheet, it should come as " ABC DCF"
Sub RenameFromA1()
Dim Msg As String, i As Integer
For i = 2 To Sheets.Count
If Sheets(i).Range("B1").Value = "" Then
Msg = "Sheet " & i & "(" & Sheets(i).Name & ") has no value in A1. Fix sheet, then rerun."
MsgBox Msg, vbExclamation
Exit Sub
Else
On Error GoTo ErrSheetName
Sheets(i).Name = Sheets(i).Range("B1").Value
On Error GoTo 0
End If
Next i
Exit Sub
ErrSheetName: Msg = "Sheet " & i & "(" & Sheets(i).Name & ") could not be renamed. Check if name already used."
MsgBox Msg, vbExclamation
End Sub
Thank you in advance
I need to exclude that error and remove the special character in the particular cell and rename as it is.
Example : B1 cell is having " ABC/ DCF"
While renaming the sheet, it should come as " ABC DCF"
Sub RenameFromA1()
Dim Msg As String, i As Integer
For i = 2 To Sheets.Count
If Sheets(i).Range("B1").Value = "" Then
Msg = "Sheet " & i & "(" & Sheets(i).Name & ") has no value in A1. Fix sheet, then rerun."
MsgBox Msg, vbExclamation
Exit Sub
Else
On Error GoTo ErrSheetName
Sheets(i).Name = Sheets(i).Range("B1").Value
On Error GoTo 0
End If
Next i
Exit Sub
ErrSheetName: Msg = "Sheet " & i & "(" & Sheets(i).Name & ") could not be renamed. Check if name already used."
MsgBox Msg, vbExclamation
End Sub
Thank you in advance