Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-19-2015, 11:45 AM
orozvik@yahoo.com orozvik@yahoo.com is offline Auto rename tab Windows 7 64bit Auto rename tab Office 2010 64bit
Novice
Auto rename tab
 
Join Date: Apr 2015
Posts: 8
orozvik@yahoo.com is on a distinguished road
Cool Auto rename tab

Anyone have a clue how to automatically rename sheet tabs to a name in a cell in another tab?



So, if sheet 1 in A2 has the Value "OAC-125" then the following tab names would be updated with that name as follows:

Sheet 2 - Current Name: DAR Updated to: OAC-125 DAR
Sheet 3 - Current Name: ZKL Updated to: OAC-125 ZKL

you get it ha? I thought maybe some formula can be entered with the concatenate symbol in each tab like this:

Sheet 2 - Sheet 1! A2 & DAR

Any idea guys/gals? thank.s
Reply With Quote
  #2  
Old 10-19-2015, 08:27 PM
macropod's Avatar
macropod macropod is offline Auto rename tab Windows 7 64bit Auto rename tab Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

A formula cannot change a sheet's name. At the very least, a macro would be required.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 10-20-2015, 12:11 AM
:) Sixthsense :)'s Avatar
:) Sixthsense :) :) Sixthsense :) is offline Auto rename tab Windows XP Auto rename tab 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
  #4  
Old 10-20-2015, 07:45 AM
orozvik@yahoo.com orozvik@yahoo.com is offline Auto rename tab Windows 7 64bit Auto rename tab Office 2010 64bit
Novice
Auto rename tab
 
Join Date: Apr 2015
Posts: 8
orozvik@yahoo.com is on a distinguished road
Smile

Hi Sixthsense,
The code works great! Thank you. However, how can I tweak it so that all four tabs are renamed at exactly the moment the text is entered in the first tab in cell D9? So, this would be a change event related to that cell? The tabs would not have the same name as the text entered in cell D9 since the value entered in cell D9 would be appended as the prefix with a space between to the existing tab names like this:

D9 = OAC

Tab 1 = 123 becomes OAC 123
Tab 2 = 789 becomes OAC 789
Tab 3 = 456 becomes OAC 456

Thanks
Reply With Quote
  #5  
Old 10-21-2015, 06:06 AM
orozvik@yahoo.com orozvik@yahoo.com is offline Auto rename tab Windows 7 64bit Auto rename tab Office 2010 64bit
Novice
Auto rename tab
 
Join Date: Apr 2015
Posts: 8
orozvik@yahoo.com is on a distinguished road
Default Solved;

With Sixthsense' help from above and some tweaking of my own I have solved the riddle.

Thus, any time cell D9 has an entry made to it whether adding in an entry or deleting an entry the tabs will update. When adding an entry the tabs will have the entry added as a prefix to the already existing tab name with a space between the newly added prefix and existing tab name.

Also, when the entry in cell D9 is deleted, the tabs will revert back to their original tab names with the prefix being removed.

Pretty cool ha? Here is the code which needs to be added to the sheet object where cell D9 will be updated in project explorer.



Quote:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim sWs As String, sCell As String, shName As String, i As Integer
If Target.Address = "$D$9" And Range("$D$9") <> "" Then
sCell = Range("D9").Value

For i = 2 To 6

sWs = Worksheets(i).Name

On Error Resume Next
shName = sCell & " " & sWs
sWs = shName
Worksheets(i).Name = sWs
On Error GoTo 0
Next i

Else

Worksheets(2).Name = "Add"
Worksheets(3).Name = "Add Remit"
Worksheets(4).Name = "Remove"
Worksheets(5).Name = "Remove Remit"
Worksheets(6).Name = "JE"


End If

End Sub
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Rename a Quick Part sleake Word 14 10-14-2013 09:21 AM
Variable to rename a tab in a worksheet via VBA Chayes Excel Programming 5 08-07-2012 02:03 AM
Rename Files gsrikanth Excel Programming 3 05-14-2012 03:03 AM
Can't rename shared calendars kenelder Outlook 0 06-02-2011 07:53 AM
Auto rename tab Rename File cksm4 Word VBA 2 02-25-2011 09:29 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:48 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft