Thread: Auto rename tab
View Single Post
 
Old 10-20-2015, 12:11 AM
:) Sixthsense :)'s Avatar
:) Sixthsense :) :) Sixthsense :) is offline Windows XP Office 2010 32bit
Novice
 
Join Date: Oct 2015
Location: India
Posts: 1
:) Sixthsense :) is on a distinguished road
Default

Check whether this event code fulfills your expectation

To Add Excel VBA Code to a Workbook / This Workbook Module

  1. Copy the code that you want to use
  2. Select the workbook in which you want to store the code
  3. Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
  4. In the Project Explorer, find your workbook, and open the list of Microsoft Excel Objects
  5. Right-click on the ThisWorkbook object, and choose View Code
  6. Where the cursor is flashing, choose Edit | Paste


Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim sWs As String, sCell As String

sWs = UCase(Sh.Name)
sCell = UCase(Sh.Range("A2").Value)

If Trim(sCell) <> "" Then
    If Left(sWs, Len(sCell)) <> sCell Then
        On Error Resume Next
            Sh.Name = sCell & " " & sWs
        On Error GoTo 0
    End If
End If

End Sub
Reply With Quote