How to use the VBA find and replace function

I like the single line function yet powerful command with VBA to perform find and replace functionality.

It’s used for String (text) find and replacement

Here is the syntax to use it,

<result string> = Replace (<string to process>, <find what>, <replace with>)

Here is a sample,

Dim sampleText As String
Dim resultString As String

sampleText = “I like Apple and Orange”

resultString = Replace (sampleText , Apple, “Berry”)

The function works in the same way with Excel, Word or Outlook.


Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>