Export (0) Print
Expand All
2 out of 6 rated this helpful - Rate this topic

Range.Replace Method

Office 2007
Returns a Boolean indicating characters in cells within the specified range. Using this method doesn’t change either the selection or the active cell.

Syntax

expression.Replace(What, Replacement, LookAt, SearchOrder, MatchCase, MatchByte, SearchFormat, ReplaceFormat)

expression   A variable that represents a Range object.

Parameters

NameRequired/OptionalData TypeDescription
WhatRequiredVariantThe string you want Microsoft Excel to search for.
ReplacementRequiredVariantThe replacement string.
LookAtOptionalVariantCan be one of the following XlLookAt constants: xlWhole or xlPart.
SearchOrderOptionalVariantCan be one of the following XlSearchOrder constants: xlByRows or xlByColumns.
MatchCaseOptionalVariantTrue to make the search case sensitive.
MatchByteOptionalVariantYou 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.
SearchFormatOptionalVariantThe search format for the method.
ReplaceFormatOptionalVariantThe replace format for the method.

Return Value
Boolean

Remarks

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.

Example

This example replaces every occurrence of the trigonometric function SIN with the function COS. The replacement range is column A on Sheet1.

Visual Basic for Applications
Worksheets("Sheet1").Columns("A").Replace _
    What:="SIN", Replacement:="COS", _
    SearchOrder:=xlByColumns, MatchCase:=True



Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.