VBA EXCEL如果找到文本,则替换整个字符串?

时间:2013-10-08 10:54:01

标签: excel-vba vba excel

如何解决VBA中的后续问题

如果string包含“SeachText”替换整个字符串。

离。

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

所以执行代码后

"Test_1_Of_The_Text_SeachString_Sth"将成为"New_Text"

以及:

"Test_2_Of_The_Text_SeachString_Sth"将成为"New_Text"

1 个答案:

答案 0 :(得分:2)

使用像这样的Instr函数:

  ip1= "Test_1_The_Text_SeachString_Sth" 
  lookfor="SeachString"

  If instr(ip1,lookfor)>0 then
     ip1= "newtext"
  End if
相关问题