ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Replace more characters using replace (https://www.excelbanter.com/excel-programming/442616-replace-more-characters-using-replace.html)

jkrons

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

James Ravenswood

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

jkrons

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 -



Dana DeLouis[_3_]

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 -




All times are GMT +1. The time now is 01:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com