Fordraiders
asked on
simplify cleaning up replace function
excel 2010 vba
userform
textbox
The code below works ok and i'm sure can be simplified , but
If a special character(s) are inside the string.
Eventually the string will become padded with <spaces>
Example:
16oz# claw hammer ! special$ amount
becomes:
16oz<space><space>claw <space>hammer<space><space ><space>sp ecial<spac e><space>a mount
it needs to be :
16oz claw hammer special amount
Thanks
fordraiders
userform
textbox
The code below works ok and i'm sure can be simplified , but
If a special character(s) are inside the string.
Eventually the string will become padded with <spaces>
Example:
16oz# claw hammer ! special$ amount
becomes:
16oz<space><space>claw <space>hammer<space><space
it needs to be :
16oz claw hammer special amount
Thanks
fordraiders
Dim cD As String
cD = UserForm2.TextBox33
' strip special characters first
cD = Replace(cD, "#", " ")
cD = Replace(cD, "!", " ")
cD = Replace(cD, "@", " ")
cD = Replace(cD, "$", " ")
cD = Replace(cD, "^", " ")
cD = Trim(cD)
Hi,
You could use
You could use
cD = Replace(Replace(cD, " ", " "), " ", " ")
Regards
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
patrick, Learn something new every day..
simple solution.
simple solution.
http://www.macrostash.com/2011/10/08/simple-regular-expression-tutorial-for-excel-vba/