Range.Replace Method 

Returns a Boolean indicating characters in cells within the specified range.

Namespace: Microsoft.Office.Interop.Excel
Assembly: Microsoft.Office.Interop.Excel (in microsoft.office.interop.excel.dll)


Dim What As Object
Dim Replacement As Object
Dim LookAt As Object
Dim SearchOrder As Object
Dim MatchCase As Object
Dim MatchByte As Object
Dim SearchFormat As Object
Dim ReplaceFormat As Object
Dim returnValue As Boolean
Dim range1 As Range
returnValue = range1.Replace(What, Replacement, LookAt, SearchOrder, MatchCase, MatchByte, SearchFormat, ReplaceFormat)


Function Replace( _
    <InAttribute()> ByVal What As Object, _
    <InAttribute()> ByVal Replacement As Object, _
    <InAttribute()> Optional ByVal LookAt As Object, _
    <InAttribute()> Optional ByVal SearchOrder As Object, _
    <InAttribute()> Optional ByVal MatchCase As Object, _
    <InAttribute()> Optional ByVal MatchByte As Object, _
    <InAttribute()> Optional ByVal SearchFormat As Object, _
    <InAttribute()> Optional ByVal ReplaceFormat As Object _
) As Boolean
bool Replace(
    [In] object What, 
    [In] object Replacement, 
    [In, Optional] object LookAt, 
    [In, Optional] object SearchOrder, 
    [In, Optional] object MatchCase, 
    [In, Optional] object MatchByte, 
    [In, Optional] object SearchFormat, 
    [In, Optional] object ReplaceFormat
public: Boolean Replace(
    Object^ What, 
    Object^ Replacement, 
    Object^ LookAt, 
    Object^ SearchOrder, 
    Object^ MatchCase, 
    Object^ MatchByte, 
    Object^ SearchFormat, 
    Object^ ReplaceFormat
public boolean Replace(
    /*in*/System.Object What, 
    /*in*/System.Object Replacement, 
    /*in*/System.Object LookAt, 
    /*in*/System.Object SearchOrder, 
    /*in*/System.Object MatchCase, 
    /*in*/System.Object MatchByte, 
    /*in*/System.Object SearchFormat, 
    /*in*/System.Object ReplaceFormat
function Replace(
     What : Object, 
     Replacement : Object, 
     LookAt : Object, 
     SearchOrder : Object, 
     MatchCase : Object, 
     MatchByte : Object, 
     SearchFormat : Object, 
     ReplaceFormat : Object
) : Boolean;


  • What
    Required Object. The string you want Microsoft Excel to search for.
  • Replacement
    Required Object. The replacement string.
  • LookAt
    Optional Object. Can be one of the following XlLookAt constants: xlWhole or xlPart.
  • SearchOrder
    Optional Object. Can be one of the following XlSearchOrder constants: xlByRows or xlByColumns.
  • MatchCase
    Optional Object. True to make the search case sensitive.
  • MatchByte
    Optional Object. You can use this argument only if you’ve selected or installed double-byte language support in Microsoft Excel. True to have double-byte characters match only double-byte characters; False to have double-byte characters match their single-byte equivalents.
  • SearchFormat
    Optional Object. The search format for the method.
  • ReplaceFormat
    Optional Object. The replace format for the method.


Using this method doesn’t change either the selection or the active cell.

The settings for LookAt, SearchOrder, MatchCase, and MatchByte are saved each time you use this method. If you don’t specify values for these arguments the next time you call the method, the saved values are used. Setting these arguments changes the settings in the Find dialog box, and changing the settings in the Find dialog box changes the saved values that are used if you omit the arguments. To avoid problems, set these arguments explicitly each time you use this method.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


Development Platforms

Windows XP Home Edition, Windows XP Professional, Windows Server 2003, and Windows 2000

Target Platforms

See Also


Range Interface
Microsoft.Office.Interop.Excel Namespace

Other Resources

Range Members