Table of contents
Collapse the table of content
Expand the table of content

Replace Function

office 365 dev account|Last Updated: 6/12/2017
1 Contributor

Description Returns a string in which a specified substring has been replaced with another substring a specified number of times. SyntaxReplace( expression,find,replace [ ,start [ ,count [ ,compare ]]] ) The Replace function syntax has thesenamed arguments:

expressionRequired. String expression containing substring to replace.
findRequired. Substring being searched for.
replaceRequired. Replacement substring.
startOptional. Position within expression where substring search is to begin. If omitted, 1 is assumed.
countOptional. Number of substring substitutions to perform. If omitted, the default value is -1, which means make all possible substitutions.
compareOptional. Numeric value indicating the kind of comparison to use when evaluating substrings. See Settings section for values.

Settings The compare argument can have the following values:

vbUseCompareOption-1Performs a comparison using the setting of the Option Compare statement.
vbBinaryCompare0Performs a binary comparison.
vbTextCompare1Performs a textual comparison.
vbDatabaseCompare2Microsoft Access only. Performs a comparison based on information in your database.

Return ValuesReplace returns the following values:

IfReplace returns
expression is zero-lengthZero-length string ("")
expression is NullAn error.
find is zero-lengthCopy of expression.
replace is zero-lengthCopy of expression with all occurences of find removed.
start > Len( expression )Zero-length string.
count is 0Copy of expression.

Remarks The return value of the Replace function is a string, with substitutions made, that begins at the position specified by start and and concludes at the end of the expression string. It is not a copy of the original string from start to finish.

© 2017 Microsoft