is there a simple way to have a tab on a worksheet the same as text in a
cell on that sheet ??
The following will work for Sheet1 with the tab name in cell A1.
Paste the following code into the code section of Sheet1:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
sName = Sheets(1).Range(quot;A1quot;)
If sName = quot;quot; Then sName = quot;Sheet1quot;
Sheets(1).Name = sName
End Sub
wrote:
gt; The following will work for Sheet1 with the tab name in cell A1.
gt;
gt; Paste the following code into the code section of Sheet1:
gt;
gt; Private Sub Worksheet_Change(ByVal Target As Excel.Range)
gt; sName = Sheets(1).Range(quot;A1quot;)
gt; If sName = quot;quot; Then sName = quot;Sheet1quot;
gt; Sheets(1).Name = sName
gt; End Sub
gt;
excuse my ignorance but what do you mean by quot;code sectionquot;
Click on Tools - Macro - Visual Basic Editor
On the left should be a VBAProject Window. Expand the items listed
until you see Sheet1 (Sheet1). Double Click on Sheet1. A VBA Code
Window will open for Sheet1.
I hope this will help get you started.Jeff,
To put in this macro right click on the worksheet tab and view code, in the
window that opens paste this code, press Alt and Q to close this window and
go back to your workbook. If you are using excel 2000 or newer you may have
to change the macro security settings to get the macro to run. To change the
security settings go to tools, macro, security, security level and set it to
medium
The code that was posted will work if your sheet is the first sheet in the
workbook, if not you may want to try this
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = quot;$A$1quot; Then
If Target.Value lt;gt; quot;quot; Then
On Error Resume Next
ActiveSheet.Name = Target.Value
On Error GoTo 0
End If
End If
End Sub
--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 amp; 2003
quot;Jeffquot; gt; wrote in message
...
gt; wrote:
gt; gt; The following will work for Sheet1 with the tab name in cell A1.
gt; gt;
gt; gt; Paste the following code into the code section of Sheet1:
gt; gt;
gt; gt; Private Sub Worksheet_Change(ByVal Target As Excel.Range)
gt; gt; sName = Sheets(1).Range(quot;A1quot;)
gt; gt; If sName = quot;quot; Then sName = quot;Sheet1quot;
gt; gt; Sheets(1).Name = sName
gt; gt; End Sub
gt; gt;
gt; excuse my ignorance but what do you mean by quot;code sectionquot;
wrote:
gt; Click on Tools - Macro - Visual Basic Editor
gt;
gt; On the left should be a VBAProject Window. Expand the items listed
gt; until you see Sheet1 (Sheet1). Double Click on Sheet1. A VBA Code
gt; Window will open for Sheet1.
gt;
gt; I hope this will help get you started.
gt;
Thanks very much that was great just what I needed to do.
next querie if I may
can you make the colour of the text or number in a cell change if a
certain criteria is met ??
Paul B wrote:
gt; Jeff,
gt; To put in this macro right click on the worksheet tab and view code, in the
gt; window that opens paste this code, press Alt and Q to close this window and
gt; go back to your workbook. If you are using excel 2000 or newer you may have
gt; to change the macro security settings to get the macro to run. To change the
gt; security settings go to tools, macro, security, security level and set it to
gt; medium
gt;
gt; The code that was posted will work if your sheet is the first sheet in the
gt; workbook, if not you may want to try this
gt;
gt; Private Sub Worksheet_Change(ByVal Target As Range)
gt; If Target.Address = quot;$A$1quot; Then
gt; If Target.Value lt;gt; quot;quot; Then
gt; On Error Resume Next
gt; ActiveSheet.Name = Target.Value
gt; On Error GoTo 0
gt; End If
gt; End If
gt;
gt; End Sub
gt;
gt;
gt;
Paul, this also works well thank you, can you advise me of a way of
using this or another formula to enable me to rename all sheets in a
work book ?? do I need to place this formula in all worksheets using the
VB editor ??
Yes Click on Format - Conditional Formatting...
gt;From here you can set the condition.Jeff, if you want to change all the sheets at one time try this
Sub Rename_All_Sheets()
'will rename all sheets in the workbook to the value in A1
Dim WS As Worksheet
For Each WS In Worksheets
WS.Name = WS.Range(quot;A1quot;).Value
Next
End Sub
To put in this macro, from your workbook right-click the workbook's icon and
pick View Code. This icon is to the left of the quot;Filequot; menu this will open
the VBA editor, in Project Explorer click on your workbook name, if you
don't see it press CTRL r to open the Project Explorer, then go to insert,
module, and paste the code in the window that opens on the right hand side,
press Alt and Q to close this window and go back to your workbook and press
alt and F8, this will bring up a box to pick the Macro from, click on the
Macro name to run it. If you are using excel 2000 or newer you may have to
change the macro security settings to get the macro to run. To change the
security settings go to tools, macro, security, security level and set it to
medium
If you want them to change names anytime you change A1 in a sheet then try
this
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Address = quot;$A$1quot; Then
If Target.Value lt;gt; quot;quot; Then
On Error Resume Next
ActiveSheet.Name = Target.Value
On Error GoTo 0
End If
End If
End Sub
use the instructions above but put the code in the thisworkbook section--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 amp; 2003
quot;Jeffquot; gt; wrote in message
...
gt; Paul B wrote:
gt; gt; Jeff,
gt; gt; To put in this macro right click on the worksheet tab and view code, in
the
gt; gt; window that opens paste this code, press Alt and Q to close this window
and
gt; gt; go back to your workbook. If you are using excel 2000 or newer you may
have
gt; gt; to change the macro security settings to get the macro to run. To change
the
gt; gt; security settings go to tools, macro, security, security level and set
it to
gt; gt; medium
gt; gt;
gt; gt; The code that was posted will work if your sheet is the first sheet in
the
gt; gt; workbook, if not you may want to try this
gt; gt;
gt; gt; Private Sub Worksheet_Change(ByVal Target As Range)
gt; gt; If Target.Address = quot;$A$1quot; Then
gt; gt; If Target.Value lt;gt; quot;quot; Then
gt; gt; On Error Resume Next
gt; gt; ActiveSheet.Name = Target.Value
gt; gt; On Error GoTo 0
gt; gt; End If
gt; gt; End If
gt; gt;
gt; gt; End Sub
gt; gt;
gt; gt;
gt; gt;
gt; Paul, this also works well thank you, can you advise me of a way of
gt; using this or another formula to enable me to rename all sheets in a
gt; work book ?? do I need to place this formula in all worksheets using the
gt; VB editor ??
- Sep 10 Mon 2007 20:39
naming tabs
close
全站熱搜
留言列表
發表留言