Replace Method

The Replace method replaces the target string within a range in a worksheet. When the search reaches the end of the specified search range, it wraps around to the beginning of the range.

Syntax

object.Replace( TargetStr, ReplaceStr, Current, Scope, Method, MatchCase, DelSelFirst, ReplaceAll, OrderByRows )

 

Parameter Type Description
TargetStr String required; target string to find
ReplaceStr String required; string to replace target string
Current Variant optional; cell to start search, if the TargetStr is found in the current cell, it is replaced with ReplaceStr then the search continues for the rest of the range
Scope wksFindScope optional; find by column, by row, or search entire worksheet; default is wksFindScopeEntire
Method wksFindMethod optional; the find method; default is wksFindExact
MatchCase Boolean optional; true to match case, default is false
DelSelFirst Boolean optional; deselect cells before search; default is true - deselect the cells
ReplaceAll Boolean optional; true to replace all occurrences of the search string, false to replace one occurrence; default is false
OrderByRows Boolean optional; Scope must be wksFindScopeEntire, true to finish searching a row before going on to the next row, false to finish searching a column before going to the next column; default is false

 

Example

This example shows how to replace the “a” in a worksheet cell with “another.”

Set Current = WksRange("A1:E4").Replace("a","another",Current,wksFindScopeEntire,wksFindExact, False,False,True,False)

 

Used by: WksCellFormat object