Link to home
Start Free TrialLog in
Avatar of Flora Edwards
Flora EdwardsFlag for Sweden

asked on

Excel VBA search and replace a string

I need a code to search dashes - into a string and if found then replace it with space

how I can do that?
Avatar of Haris Dulic
Haris Dulic
Flag of Austria image

Use this formula

=+SUBSTITUTE(A1;"-";" ")

Where A1 iscell with your data
Avatar of Flora Edwards

ASKER

I know Subs  formula.  my question is on how to use the vba built in function "Replace"  in VBA not in Built in function of Excel
SOLUTION
Avatar of Haris Dulic
Haris Dulic
Flag of Austria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Norie
Norie

This is how you would use replace.

Dim strAString As String

    strAString  ="A-test-string"

    MsgBox Replace(strAString, "-"," ")

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you guys

last query on this,   if I want to replace dashes and underscores - & _ with space
how can this be done?  does it require two times replace or ampersand can be used in replace?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
two times replace..