Replace Method

This method finds and replaces specified data in all cells in a range. It has no effect on the selection or the active cell. The syntax is:

RangeObject.Replace(What, Replacement, LookAt, SearchOrder, MatchCase, MatchByte)

The What parameter is the data to search for, and the Replacement parameter is the replacement data. These data can be strings or any other valid Excel data types (numbers, dates, etc.).

The LookAt parameter is one of the following constants that determines whether the What value must match the cell's entire contents or just any part of the cell's contents:

Enum XlLookAt xlWhole = 1 xlPart = 2 End Enum

The SearchOrder parameter is one of the following XlSearchOrder constants:

Enum XlSearchOrder xlByRows = 1 xlByColumns = 2 End Enum

The MatchCase parameter should be set to True to do a case-sensitive search (the default is False). The MatchByte parameter is used only in the Far East version of Microsoft Excel. See the help documentation for details.

Note that the values of the LookAt, SearchOrder, MatchCase, and MatchByte parameters are saved each time the Find method is invoked and then reused for the next call to this method. Note also that setting these arguments changes the corresponding settings in Excel's Find dialog box, and conversely, changing the settings in the Find dialog box changes the values of these parameters. This implies that we cannot rely on the values of these parameters, since the user may have changed them through the Find dialog box. Hence, it is important to specify each of these arguments for each call to the Find method.

If the contents of the What argument are found at least once, the Replace method returns True.

0 0

Post a comment