gaffcz
gaffcz

Reputation: 3479

VBA: Split and change string

I need to change e.g. following string 153,154,155,156

to 153**,**154**,**155**,**156

so the , to **,**

How can I do that in VBA?

Upvotes: 1

Views: 154

Answers (3)

Dick Kusleika
Dick Kusleika

Reputation: 33175

Not better, but different:

Sub SplitJoin()

    Debug.Print Join(Split("153,154,155,156", ","), "**,**")

End Sub

Upvotes: 4

Daren Thomas
Daren Thomas

Reputation: 70344

Try this:

Dim s as String
s = "153,154,155,156"
s = Replace(s, ",", "**,**")

Upvotes: 3

user2140173
user2140173

Reputation:

Replace() on MSDN

Sub ReplaceInStr()

    Dim str As String
    str = "153,154,155,156"
    str = Replace(str, ",", "**,**")
    MsgBox str

End Sub

Upvotes: 4

Related Questions