Home |
Search |
Today's Posts |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Using my response to your previous question as a basis (since I assume you
still want to replace all the bad characters and not just the slash), here is a new function (I changed the name slightly) modified to do this additional request... Function FixName(ProposedName As String) As String Dim V As Variant, WS As Worksheet, Counter As Long FixName = ProposedName For Each V In Array("\", "/", "?", "*", "[", "]") FixName = Replace(FixName, V, "") Next FixName = Left(FixName, 31) For Each WS In Worksheets If InStr(1, WS.Name, FixName, vbTextCompare) Then Counter = Counter + 1 Next If Counter Then FixName = FixName & "(" & (Counter + 1) & ")" End Function What this function will do is add (2) if the name already exists and add (3) if the name and the (2) version of the name both exist and so on. You would install the function the same way I gave you in my other post, namely, put it into a Module... click Insert/Module from the VB menu bar. Then, all you have to do in your code is this... ActiveSheet.Name = FixName(ActiveCell.Value) -- Rick (MVP - Excel) "al" wrote in message ... Sub SheetNameActivecell() Application.ActiveSheet.Name = Left(Application.Substitute (ActiveCell.Value, "/", ""), 31) End Sub Would also like to improve macro by adding codes which would allow to name a sheet with (2) at end of an existing sheet name. e.g if "Google" already exist - macro would rename sheet as "Google (2)" Thxs |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Creating a new sheet from specific data in existing sheet | Excel Discussion (Misc queries) | |||
copying an existing sheet | Excel Programming | |||
Create a new sheet from an existing sheet | Excel Programming | |||
Copy rows onto existing sheet / start a new sheet if full | Excel Programming | |||
Copy the entire sheet to overlay existing sheet? | New Users to Excel |