Macro to name sheet tabs

B

Bill_S

I need a macro that will automatically name the sheet tab the date that I
enter in cell E4 on my worksheet. I tried the following macro:

Sub Worksheet_Change ()
ws.Name = ws.Range("E4").Value
End Sub

It automatically runs when I enter a new date in cell E4, which is good.
What isn't good is that it gives the following error message:

"Compile error: Procedure declaration does not match description of event or
procedure having the same name."

How can I get this macro to work?
 
G

Gary''s Student

Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Range("E4")
Set t = Target
If Intersect(t, r) Is Nothing Then Exit Sub
ActiveSheet.Name = r.Value
End Sub

In the worksheet code area
 
D

Don Guillett

Private Sub Worksheet_Change(ByVal Target As Range)
if target.address<>"$E$4" then exit sub
activesheet.name=target
end sub
 
B

Bill_S

Excellent! Thank you!
-Bill

Gary''s Student said:
Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Range("E4")
Set t = Target
If Intersect(t, r) Is Nothing Then Exit Sub
ActiveSheet.Name = r.Value
End Sub

In the worksheet code area
 
B

Bill_S

Don- thx for the streamlined version too!
-Bill

Don Guillett said:
Private Sub Worksheet_Change(ByVal Target As Range)
if target.address<>"$E$4" then exit sub
activesheet.name=target
end sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top