Tuesday, February 5, 2013

REPLACE function (VBA)

In Microsoft Excel, the REPLACE function replaces a sequence of characters in a string with another set of characters. Please note that the worksheet version of the REPLACE function has different syntax.


Syntax:-
 
The syntax for the REPLACE function is:
 
Replace ( string1, find, replacement, [start, [count, [compare]]] )string1 is the string to replace a sequence of characters with another set of characters.

  • find is the string that will be searched for in string1.
  • replacement will replace find in string1.
  • start is optional. This is the position in string1 to begin the search. If this parameter is omitted, the REPLACE function will begin the search at position 1.
  • count is optional. This is the number of occurrences to replace. If this parameter is omitted, the REPLACE function will replace all occurrences of find with replacement.
 
VBA Function Example:-
 
The REPLACE function can be used in VBA code. Here are some examples of what the REPLACE function would return:

Replace("cpalani1", "palani1", "hidambaram") would return "chidambaram"

No comments: