vba to Rename specifc worksheet based on cell value with 'illegal' character (/)

  • I have a workbook with a specific sheet ("testa")with special characters (:/\?*[])? in a specific cell F2 value reads "MERCEND/FF." .


    I have found a code below while googling but how to adjust for a specific sheet "MERCEND/FF." of the workbook. to rename the sheet by CELL F2 replacing the special character with either _or - or space


    e.g "MERCEND FF." or "MERCEND-FF." or "MERCEND-FF." that is rename testa sheet to cell F2 value



    Sub tabname() Dim ws As Worksheet For Each ws In Worksheets On Error Resume Next If Len(ws.Range("F2")) >0 Then ws.Name = ws.Range("F2").Value End If On Error Goto 0 If ws.Name <> ws.Range("F2").Value Then Msgbox ws.Name & " Was Not renamed, the suggested name was invalid" End If Next End Sub


    Apolgize ,I am having some issue to insert tags

  • HTML
    Sub tabname() Dim ws As Worksheet For Each ws In Worksheets     On Error Resume Next     If Len(ws.Range("F2")) >0 Then         ws.Name = ws.Range("F2").Value     End If     On Error Goto 0     If ws.Name <> ws.Range("F2").Value Then         Msgbox ws.Name & " Was Not renamed, the suggested name was invalid"     End If Next End Sub
  • You need to use code tags rather than HTML tags for VBA code.


    If you are trying to rename each sheet in a workbook based on the value of cell F2 in each sheet, maybe try the following:


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!