Gall Anonim
Gall Anonim

Reputation: 1

VBA EXCEL Replace whole string if text found in it?

how can i resovlve the follwing issue in VBA

if string contains "SeachText" replace whole string.

ex.

input:        "Test_1_The_Text_SeachString_Sth" 
input:        "Test_2_The_Text_SeachString_Sth" 
look for:     "SeachrString"
replace with  "New_Text"

so after execute the code the

"Test_1_Of_The_Text_SeachString_Sth" will become "New_Text"

as well as:

"Test_2_Of_The_Text_SeachString_Sth" will become "New_Text"

Upvotes: 0

Views: 1414

Answers (1)

Kamal G
Kamal G

Reputation: 278

Use Instr function like this:

  ip1= "Test_1_The_Text_SeachString_Sth" 
  lookfor="SeachString"

  If instr(ip1,lookfor)>0 then
     ip1= "newtext"
  End if

Upvotes: 2

Related Questions