View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default VBA Replace using wildcard?

Try this (record a macro just in case it works!)

Select the range to fix
edit|replace
what: <td * (I included a space character--just to be more specific)
with: <td
replace all

Did it do what you want?

If yes, keep the macro. If no, then Edit|Undo and toss the macro.


Post Tenebras Lux wrote:

I have a very long string (an HTML document).

I want to replace all instances of a substring for which I know the first
few characters and the end character, but the middle part of the substring
can vary in both length and additional characters.

For example, if I want to replace each of the following using the Replace
function and wildcards:
<td class="dkbluelt" with <td
<td valign="top" bgcolor=#99cbe5" align="left" with <td

I have built a for loop using Instr and Mid functions, but it takes a long
time to run.

Is there any way to use the replace function in VBA using wildcards? for
example:
Result = Replace(MyLongString, "<td*", "<td")

Thanks for any suggestions.


--

Dave Peterson