Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 3
Default How to Remove Forbidden Characters

I need a formula that will remove forbidden characters and blank spaces. Examples of characters I'd like to remove are .,’;<?:”!@#$%^&*. Thank you for any assistance you can provide!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,045
Default How to Remove Forbidden Characters

On Wed, 11 Jul 2012 14:33:25 +0000, rsexcel wrote:


I need a formula that will remove forbidden characters and blank spaces.
Examples of characters I'd like to remove are .,’;<?:”!@#$%^&*.
Thank you for any assistance you can provide!


For a regular worksheet formula, you can use nested SUBSTITUTE functions, with the nesting depth limited by the version of Excel you are using.

eg:
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,". ",""),",",""),"<",""),"","")

Extend as necessaary.

For a VBA solution:


To enter this User Defined Function (UDF), <alt-F11 opens the Visual Basic Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.

To use this User Defined Function (UDF), enter a formula like

=RemForbidden(cell_ref)

in some cell.

=============================
Option Explicit
Function RemForbidden(s As String) As String
Dim re As Object
Dim sForbidden As String
Set re = CreateObject("vbscript.regexp")

'There are special rules for certain characters
' A hyphen must appear first or last
' A right bracket (]) must be preceded by a forward slash
' e.g: \]

sForbidden = ".,’;<?:”!@#$%^&*"

With re
.Global = True
.Pattern = "[" & sForbidden & "]*"
End With

RemForbidden = re.Replace(s, "")
End Function
=====================================
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
Copying all whilst Range Forbidden active donh[_2_] Excel Programming 8 January 27th 11 09:03 AM
Site for some reason, and forbidden alagmy Excel Worksheet Functions 0 May 6th 10 10:22 PM
Remove characters Lotto[_2_] Excel Programming 1 March 15th 10 12:41 AM
Remove top bit characters Brett... Excel Discussion (Misc queries) 8 February 9th 06 05:38 PM
easy way to check for forbidden characters? Ouka[_26_] Excel Programming 2 December 21st 05 10:01 PM


All times are GMT +1. The time now is 12:24 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"