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



如何在 VBA 中重新解决以下问题

如果字符串包含"搜索文本",则替换整个字符串。

前任。

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"

像这样使用 Instr 函数:

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

最新更新