View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default replace() funciton with multiple tests....

Hi Matthew,

Am Mon, 28 Nov 2016 15:53:19 -0800 (PST) schrieb Matthew Dyer:

Replace(string, Or("purge_", "dealdrop_"), "cor010_wcout")

I've tried Replace(string, Array("purge_", "dealdrop_"), "cor010_wcout") which also doesn't work.

since i'll never be in a situation where string will contain both purge_ and dealdrop_ I've gone the route of running the replace function twice as follows:

tempstring = Replace(string, "purge_", "cor010_wcout")
tempstring = Replace(string, "dealdrop_", "cor010_wcout")


you can nest to functions:
tempstring = Replace(Replace(string, "purge_", "cor010_wcout"), "dealdrop_", "cor010_wcout")

or you can do it with an array:

varRep = Array("purge_", "dealdrop")
For i = LBound(varRep) To UBound(varRep)
tempstring = Replace(string, varRep(i), "cor010_wcout")
Next


Regards
Claus B.
--
Windows10
Office 2016