Solved

Auto Changing a Sheet Name based on cell value

Posted on 2016-10-03
9
55 Views
Last Modified: 2016-10-25
Hello,
I currently have a workbook that I am trying to have the tab name reflect what is in the sheets cell "A1" for every sheet.  I currently have the code set up as below, however it requires that I click each tab in order to get it to change, is there a way to get it to do this function without having to click the sheet tab?

Private Sub Worksheet_Activate()
On Error Resume Next
Me.Name = Range("a1").Value
End Sub
0
Comment
Question by:christina Ridings
  • 3
  • 2
9 Comments
 
LVL 30

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41827043
You may have this sub-routine on a Standard Module and run this to rename all the sheets.

Sub ChangeSheetNames()
Dim ws As Worksheet
On Error Resume Next
For Each ws In Worksheets
   If ws.Range("A1").Value <> "" Then
      ws.Name = ws.Range("A1").Value
   End If
Next ws
End Sub

Open in new window

0
 
LVL 45

Accepted Solution

by:
aikimark earned 250 total points (awarded by participants)
ID: 41827051
Can put code into the Workbook_Open() event that will iterate through the worksheets.
0
 
LVL 8

Assisted Solution

by:Koen
Koen earned 250 total points (awarded by participants)
ID: 41827135
Also maybe test your A1 value for illegal characters and length
(21 characters max, symbols not allowed are  \ ? / : [ ] *)
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 30

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41827424
@Koen
On Error Resume Next would take care of all those issues.
Also the max characters allowed are 31 not 21.
0
 
LVL 8

Expert Comment

by:Koen
ID: 41827596
I just use a function for files and sheets that removes the illegale characters...skipping it usually is not what the customer wants.
0
 
LVL 30

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41858241
As per the objection raised in Post ID: 41848750.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question