Naming a sheet

D

Darin Kramer

Howdie,

I need to run a macro from within a sheet (currently called data), that
does several things to the sheet, the last being to rename the sheet to
the contents of cellb2.
Whats the vb to rename a sheet to b2...?

Thanks

D

*** Sent via Developersdex http://www.developersdex.com ***
 
P

Peter Rooney

Darin,

This should do - paste it into the Code module of the "Data" worksheet

Whenever you change the value in the cell with the name "TabName" (you can
replace this with a cell reference if you want), the tabname will change to
that value, renaming the worksheet accordingly.

Regards

Pete



Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False

If Target.Address = Range("TabName").Address Then
Me.Name = Format(Target.Value)
End If
ws_exit:
Application.EnableEvents = True

End Sub
 

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

Top