naming a tab based on a cells value

  • Thread starter Thread starter a.cunje
  • Start date Start date
A

a.cunje

Is there a way to name a sheet/tab by a value which is in A1 on its
corresponding sheet?

~Andrew
 
i found this

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
If Target.Address = "$A$1" Then Sh.Name = Target
End Sub


but i dont know how to implement it...where the heck do i put it?
 
Put this in the Workbook module

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Range)

Dim EndNumber as String
On Error resume next
EndNumber = 0
sh.Name = sh.Range("a1").Value
Retest:
if err.number <> 0 then
EndNumber=EndNumber + 1
err.clear
sh.Name = sh.Range("a1").Value + "(" + EndNumber + ")"
goto Retest
end if

end sub

If there is already a sheet with the same name, this will add a 1, 2, etc at
the end. If you put it in the workbook module, it should run automatically.
 

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

Back
Top