Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default change sheet name based on cell

Hi

I have searched through here and found some similar questions but none of
the answers seem to work for me. I have a work book with approx 20 sheets
each for a different team, and each sheet has the team name in A1 that I need
reflected in the sheet name. The cell information may change as the team
name changes. Any help would be greatly appreciated!

Cheers
Soph
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default change sheet name based on cell

Set the security level to low/medium in (Tools|Macro|Security). From workbook
press Alt+F11 to launch VBE (Visual Basic Editor). From the left treeview
search for the workbook name and click on + to expand it. Within that you
should see the following

VBAProject(Your_Filename)
Microsoft Excel Objects
Sheet1(Sheet1)
Sheet2(Sheet2)
Sheet3(Sheet3)
This Workbook

Double click 'This WorkBook' and paste the below code to the right code pane.

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
On Error Resume Next
If Target.Count = 1 And Target.Address = "$A$1" Then
If Trim(Target.Text) < "" Then Sh.Name = Trim(Range("A1"))
End If
End Sub


PS: Sheetname Max length 31 and exxception characters are [ ] * ? / \

If this post helps click Yes
---------------
Jacob Skaria


"soph" wrote:

Hi

I have searched through here and found some similar questions but none of
the answers seem to work for me. I have a work book with approx 20 sheets
each for a different team, and each sheet has the team name in A1 that I need
reflected in the sheet name. The cell information may change as the team
name changes. Any help would be greatly appreciated!

Cheers
Soph

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default change sheet name based on cell

perfect thanks! at first I couldn't get it to work but then realised that A1
can't be the result of a lookup formula? when I changed this to a simple
values only it was dead on cheers

"Jacob Skaria" wrote:

Set the security level to low/medium in (Tools|Macro|Security). From workbook
press Alt+F11 to launch VBE (Visual Basic Editor). From the left treeview
search for the workbook name and click on + to expand it. Within that you
should see the following

VBAProject(Your_Filename)
Microsoft Excel Objects
Sheet1(Sheet1)
Sheet2(Sheet2)
Sheet3(Sheet3)
This Workbook

Double click 'This WorkBook' and paste the below code to the right code pane.

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
On Error Resume Next
If Target.Count = 1 And Target.Address = "$A$1" Then
If Trim(Target.Text) < "" Then Sh.Name = Trim(Range("A1"))
End If
End Sub


PS: Sheetname Max length 31 and exxception characters are [ ] * ? / \

If this post helps click Yes
---------------
Jacob Skaria


"soph" wrote:

Hi

I have searched through here and found some similar questions but none of
the answers seem to work for me. I have a work book with approx 20 sheets
each for a different team, and each sheet has the team name in A1 that I need
reflected in the sheet name. The cell information may change as the team
name changes. Any help would be greatly appreciated!

Cheers
Soph

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default change sheet name based on cell

Try the below...

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Range("A1") < Sh.Name And Trim(Range("A1")) < "" Then _
Sh.Name = Trim(Range("A1"))
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"soph" wrote:

perfect thanks! at first I couldn't get it to work but then realised that A1
can't be the result of a lookup formula? when I changed this to a simple
values only it was dead on cheers

"Jacob Skaria" wrote:

Set the security level to low/medium in (Tools|Macro|Security). From workbook
press Alt+F11 to launch VBE (Visual Basic Editor). From the left treeview
search for the workbook name and click on + to expand it. Within that you
should see the following

VBAProject(Your_Filename)
Microsoft Excel Objects
Sheet1(Sheet1)
Sheet2(Sheet2)
Sheet3(Sheet3)
This Workbook

Double click 'This WorkBook' and paste the below code to the right code pane.

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
On Error Resume Next
If Target.Count = 1 And Target.Address = "$A$1" Then
If Trim(Target.Text) < "" Then Sh.Name = Trim(Range("A1"))
End If
End Sub


PS: Sheetname Max length 31 and exxception characters are [ ] * ? / \

If this post helps click Yes
---------------
Jacob Skaria


"soph" wrote:

Hi

I have searched through here and found some similar questions but none of
the answers seem to work for me. I have a work book with approx 20 sheets
each for a different team, and each sheet has the team name in A1 that I need
reflected in the sheet name. The cell information may change as the team
name changes. Any help would be greatly appreciated!

Cheers
Soph

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default change sheet name based on cell

Forgot to mention that this code will work even if you have a formula (like
vlookup) in cell A1.

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

Try the below...

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Range("A1") < Sh.Name And Trim(Range("A1")) < "" Then _
Sh.Name = Trim(Range("A1"))
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"soph" wrote:

perfect thanks! at first I couldn't get it to work but then realised that A1
can't be the result of a lookup formula? when I changed this to a simple
values only it was dead on cheers

"Jacob Skaria" wrote:

Set the security level to low/medium in (Tools|Macro|Security). From workbook
press Alt+F11 to launch VBE (Visual Basic Editor). From the left treeview
search for the workbook name and click on + to expand it. Within that you
should see the following

VBAProject(Your_Filename)
Microsoft Excel Objects
Sheet1(Sheet1)
Sheet2(Sheet2)
Sheet3(Sheet3)
This Workbook

Double click 'This WorkBook' and paste the below code to the right code pane.

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
On Error Resume Next
If Target.Count = 1 And Target.Address = "$A$1" Then
If Trim(Target.Text) < "" Then Sh.Name = Trim(Range("A1"))
End If
End Sub


PS: Sheetname Max length 31 and exxception characters are [ ] * ? / \

If this post helps click Yes
---------------
Jacob Skaria


"soph" wrote:

Hi

I have searched through here and found some similar questions but none of
the answers seem to work for me. I have a work book with approx 20 sheets
each for a different team, and each sheet has the team name in A1 that I need
reflected in the sheet name. The cell information may change as the team
name changes. Any help would be greatly appreciated!

Cheers
Soph

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change formating in other sheet cell based on match condition Brandon[_2_] Excel Programming 6 September 2nd 09 09:41 AM
Change sheet names based on cell contents Jim G Excel Programming 6 June 19th 09 11:47 AM
Change sheet name based on cell value from another sheet tab JDaywalt Excel Programming 2 March 24th 08 03:36 PM
Help: auto-copy entire rows from 1 sheet (based on cell criteria) to another sheet. bertbarndoor Excel Programming 4 October 5th 07 04:00 PM
How can I change sheet tab color based on cell value in sheet? SCAScot Excel Programming 2 November 23rd 05 09:47 PM


All times are GMT +1. The time now is 07:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"