using vba name worksheet same as a cell
Personally, I'd deal with it using the Worksheet_Change() event rather than
the SelectionChange() event. Every time that you select a new cell or group
of cells, your current routine is being called. It really only needs to be
called when the contents of G1 changes. This code will do that for you:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$G$1" Then
ActiveSheet.Name = Range("G1").Value
End If
End Sub
Just delete your existing code entirely and put the code above in the same
worksheet code module where the old code was.
"Wanna Learn" wrote:
Hello
Below is the code I've been using,
now I want to change to code so that instead of a date is the word on cell G1
How do I correct this thanks
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With ActiveSheet
newname = Application.WorksheetFunction.Text(Range("G1"), "mm-dd-yy")
ActiveSheet.Name = newname
End With
End Sub
|