Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 64
Default Rename sheet by removing any invalid character

I'm currently using macro below to remove / as invalid character and
keep the character limit to 31. However i would also like to add the
other invalid characters ? \ [ ] * so that i can provide for more
invalid characters - Pls help thxs

Sub SheetNameActivecell()

Application.ActiveSheet.Name = Left(Application.Substitute
(ActiveCell.Value, "/", ""), 31)

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 563
Default Rename sheet by removing any invalid character

Sub SheetNameActivecell()
Dim BadSym(6)
BadSym(1) = "/"
BadSym(2) = "\"
BadSym(3) = "?"
BadSym(4) = "["
BadSym(5) = "]"
BadSym(6) = "*"
NewName = ActiveCell.Value
'MsgBox NewName
For k = 1 To 6
NewName = Replace(NewName, BadSym(k), "")
'MsgBox NewName
Next k
Application.ActiveSheet.Name = Left(NewName, 31)
End Sub

best wishes
--
Bernard Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme

"al" wrote in message
...
I'm currently using macro below to remove / as invalid character and
keep the character limit to 31. However i would also like to add the
other invalid characters ? \ [ ] * so that i can provide for more
invalid characters - Pls help thxs

Sub SheetNameActivecell()

Application.ActiveSheet.Name = Left(Application.Substitute
(ActiveCell.Value, "/", ""), 31)

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Rename sheet by removing any invalid character

Here is a function you can use to "fix" the proposed name by purging it of
the bad characters and truncating the proposed name to no more than 31
characters..

Function FixedName(ProposedName As String) As String
Dim V As Variant
FixedName = ProposedName
For Each V In Array("\", "/", "?", "*", "[", "]")
FixedName = Replace(FixedName, V, "")
Next
FixedName = Left(FixedName, 31)
End Function

So, after installing this function (probably best to put it into a Module...
click Insert/Module from the VB menu bar), just do this in your code...

ActiveSheet.Name = FixedName(ActiveCell.Value)

--
Rick (MVP - Excel)


"al" wrote in message
...
I'm currently using macro below to remove / as invalid character and
keep the character limit to 31. However i would also like to add the
other invalid characters ? \ [ ] * so that i can provide for more
invalid characters - Pls help thxs

Sub SheetNameActivecell()

Application.ActiveSheet.Name = Left(Application.Substitute
(ActiveCell.Value, "/", ""), 31)

End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 64
Default Rename sheet by removing any invalid character

On Jan 13, 9:30 pm, "Rick Rothstein"
wrote:
Here is a function you can use to "fix" the proposed name by purging it of
the bad characters and truncating the proposed name to no more than 31
characters..

Function FixedName(ProposedName As String) As String
Dim V As Variant
FixedName = ProposedName
For Each V In Array("\", "/", "?", "*", "[", "]")
FixedName = Replace(FixedName, V, "")
Next
FixedName = Left(FixedName, 31)
End Function

So, after installing this function (probably best to put it into a Module...
click Insert/Module from the VB menu bar), just do this in your code...

ActiveSheet.Name = FixedName(ActiveCell.Value)

--
Rick (MVP - Excel)

"al" wrote in message

...

I'm currently using macro below to remove / as invalid character and
keep the character limit to 31. However i would also like to add the
other invalid characters ? \ [ ] * so that i can provide for more
invalid characters - Pls help thxs


Sub SheetNameActivecell()


Application.ActiveSheet.Name = Left(Application.Substitute
(ActiveCell.Value, "/", ""), 31)


End Sub


thxs
  #5   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 64
Default Rename sheet by removing any invalid character

On Jan 13, 9:14 pm, "Bernard Liengme"
wrote:
Sub SheetNameActivecell()
Dim BadSym(6)
BadSym(1) = "/"
BadSym(2) = "\"
BadSym(3) = "?"
BadSym(4) = "["
BadSym(5) = "]"
BadSym(6) = "*"
NewName = ActiveCell.Value
'MsgBox NewName
For k = 1 To 6
NewName = Replace(NewName, BadSym(k), "")
'MsgBox NewName
Next k
Application.ActiveSheet.Name = Left(NewName, 31)
End Sub

best wishes
--
Bernard Liengme
Microsoft Excel MVPhttp://people.stfx.ca/bliengme

"al" wrote in message

...

I'm currently using macro below to remove / as invalid character and
keep the character limit to 31. However i would also like to add the
other invalid characters ? \ [ ] * so that i can provide for more
invalid characters - Pls help thxs


Sub SheetNameActivecell()


Application.ActiveSheet.Name = Left(Application.Substitute
(ActiveCell.Value, "/", ""), 31)


End




thxs

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i rename a sheet if the rename tab is inactive? Nelson Excel Worksheet Functions 1 March 3rd 10 10:28 AM
Removing character in a string MikeL Excel Discussion (Misc queries) 2 December 3rd 09 08:11 PM
Removing a character sjs Excel Worksheet Functions 4 November 14th 07 09:29 PM
In excell, I put an invalid character on a worksheet name tab, no. lyk New Users to Excel 3 December 27th 04 01:48 AM
Removing invalid characters from proposed sheet name Ron McCormick[_2_] Excel Programming 2 May 4th 04 06:31 PM


All times are GMT +1. The time now is 02:38 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"