I have a string in VBA - Hello how are you
.
I want to replace -
with something else. How can I do that? I am beginning in VBA. Need help.
The easiest way would be to use the replace function.
For example:
Dim yourString As String
Dim newString As String
yourString = "- Hello how are you"
newString = Replace(yourString, "-", "something else")
MsgBox newString 'returns "something else Hello how are you"
If it's always the first character and that character is different for each string you can do something like this:
Dim yourString, subString, replacementString, newString As String
yourString = "- Hello how are you"
subString = Right(yourString, Len(yourString) - 1)
replacementString = "something else"
newString = replacementString + subString
MsgBox newString 'returns "something else Hello how are you"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With