VBA Replace Function: The Replace function in VBA searches for a substring within the specified string and replaces its occurrences with a second substring.



Expression (required) – This parameter represents string that you want to search.

Find (required) – It represents the substring that you want to find and replace.

Replace (required) – This parameter represents a substring that you want to replace with the Find substring. The default value is 1.

Start (optional) – This parameter represents the position within the Expression that the string should start at.

Count (optional) – It signifies the number of occurrences of the Find substring that you want to replace. The default value is -1.  

Compare (optional) – This parameter represents the type of comparison to make. The default value is vbBinaryCompare.

It can take any of the following values:

  • vbBinaryCompare (default value): To perform a binary comparison
  • vbTextCompare: To perform a text comparison
  • vbDatabaseCompare: To perform a database comparison


This function returns a string after replacing the specified substring with another given substring.

Example 1


Hello VBA. Welcome to VBA world!

Example 2


e to VBA world!

Example 3


Hello . Welcome to world!

Pin It on Pinterest

Share This