View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_3_] Dave Peterson[_3_] is offline
external usenet poster
 
Posts: 2,824
Default VB String Comparison In Excel

One cell???

then I'd do something like:

Option Explicit
Sub testme()

Dim myWords As Variant
Dim iCtr As Long
Dim rng As Range
Dim myStr As String

myWords = Array("P/N", "(ALT)", "(OLD)", "(NEW)", _
"-", "\", "/", "[", "]", "(", ")", "~*")

Set rng = Worksheets("sheet1").Range("a1")

myStr = rng.Value
For iCtr = LBound(myWords) To UBound(myWords)
myStr = Application.Substitute(myStr, myWords(iCtr), "")
Next iCtr

rng.Value = myStr

End Sub

Notice that the asterisk became ~* and I rearranged the strings so that I did
P/N before the slash character and the same with the parentheses!

If you add the question mark, you'll need ~? (and same for the tilde itself ~
becomes ~~).

If you have multiple cells, it might be quicker to do a bunch of Edit|replaces
against those cells--instead of looping though each of the cells.



Craig wrote:

I want to program code in VB in Excel that eliminates
certain characters from a particular cell. The characters
a

- \ / [ ] ( ) * P/N (ALT) (OLD) (NEW)

There are some others, but these are the
characters/substrings I wish to eliminate. How would
something like that start out? If anyone has any tips,
please let me know. Thank you...

Craig


--

Dave Peterson