Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Replace more characters using replace

Hi

I have number of characters in a string, that I like to replace with
"nothing". I use a code like this:

Sub test()
Dim a As String
a = "Jan+& Per"
a = Replace(a, " ", "")
a = Replace(a, "&", "")
a = Replace(a, "+", "")
MsgBox a
End Sub


As I have about 15 characters, that all should be replaced with
nothing, I am looking ofr another way to it. Something like

Sub test()
Dim a As String
a = "Jan+& Per"
a = Replace(a, {" ", "&", "+"}, "")
MsgBox a
End Sub

Is this possible at all?

Jan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 143
Default Replace more characters using replace

On May 18, 5:13*am, jkrons wrote:
Hi

I have number of characters in a string, that I like to replace with
"nothing". I use a code like this:

Sub test()
* * Dim a As String
* * a = "Jan+& Per"
* * a = Replace(a, " ", "")
* * a = Replace(a, "&", "")
* * a = Replace(a, "+", "")
* * MsgBox a
End Sub

As I have about 15 characters, that all should be replaced with
nothing, I am looking ofr another way to it. Something like

Sub test()
* * Dim a As String
* * a = "Jan+& Per"
* * a = Replace(a, {" ", "&", "+"}, "")
* * MsgBox a
End Sub

Is this possible at all?

Jan


You can always use a loop:

Sub EasyAsABC()
a = "ABCDEFG"
chn = Array("A", "B", "C")
For i = 0 To UBound(chn)
a = Replace(a, chn(i), "")
Next
MsgBox a
End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Replace more characters using replace

Of Course!. Thank you.

Jan


On 18 Maj, 12:57, James Ravenswood wrote:
On May 18, 5:13*am, jkrons wrote:





Hi


I have number of characters in a string, that I like to replace with
"nothing". I use a code like this:


Sub test()
* * Dim a As String
* * a = "Jan+& Per"
* * a = Replace(a, " ", "")
* * a = Replace(a, "&", "")
* * a = Replace(a, "+", "")
* * MsgBox a
End Sub


As I have about 15 characters, that all should be replaced with
nothing, I am looking ofr another way to it. Something like


Sub test()
* * Dim a As String
* * a = "Jan+& Per"
* * a = Replace(a, {" ", "&", "+"}, "")
* * MsgBox a
End Sub


Is this possible at all?


Jan


You can always use a loop:

Sub EasyAsABC()
a = "ABCDEFG"
chn = Array("A", "B", "C")
For i = 0 To UBound(chn)
* * a = Replace(a, chn(i), "")
Next
MsgBox a
End Sub- Skjul tekst i anførselstegn -

- Vis tekst i anførselstegn -


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default Replace more characters using replace

As I have about 15 characters
{" ", "&", "+"}...etc


Hi. One idea might be to use only 1 string...

Sub YourCode()
Dim a As String
a = "Jan+& Per"
StringReplace a, " &+"
End Sub

Function StringReplace(ByRef Str, s)
Dim p
For p = 1 To Len(s)
Str = Replace(Str, Mid$(s, p, 1), vbNullString)
Next p
End Function

= = = = = = =
HTH :)
Dana DeLouis



On 5/18/2010 7:47 AM, jkrons wrote:
Of Course!. Thank you.

Jan


On 18 Maj, 12:57, James wrote:
On May 18, 5:13 am, wrote:





Hi


I have number of characters in a string, that I like to replace with
"nothing". I use a code like this:


Sub test()
Dim a As String
a = "Jan+& Per"
a = Replace(a, " ", "")
a = Replace(a, "&", "")
a = Replace(a, "+", "")
MsgBox a
End Sub


As I have about 15 characters, that all should be replaced with
nothing, I am looking ofr another way to it. Something like


Sub test()
Dim a As String
a = "Jan+& Per"
a = Replace(a, {" ", "&", "+"}, "")
MsgBox a
End Sub


Is this possible at all?


Jan


You can always use a loop:

Sub EasyAsABC()
a = "ABCDEFG"
chn = Array("A", "B", "C")
For i = 0 To UBound(chn)
a = Replace(a, chn(i), "")
Next
MsgBox a
End Sub- Skjul tekst i anførselstegn -

- Vis tekst i anførselstegn -


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
Use of Wildcard characters with replace tonuab Excel Discussion (Misc queries) 2 November 6th 09 09:39 PM
Replace last three characters Phillips via OfficeKB.com Excel Programming 3 February 12th 08 04:54 PM
Replace non printable characters TonyL Excel Worksheet Functions 4 August 25th 07 01:03 PM
Replace pattern of characters Fernando Excel Discussion (Misc queries) 5 March 21st 07 09:33 PM
Replace characters with symbols Michael Excel Programming 2 October 27th 06 02:37 PM


All times are GMT +1. The time now is 11:31 AM.

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

About Us

"It's about Microsoft Excel"