首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 办公应用 > OFFICE教程 >

range对象中replace()函数出错!解决思路

2012-01-06 
range对象中replace()函数出错!!定义了一个range对象,设置区域为一个单元格:就是一个单元格。调用replace函

range对象中replace()函数出错!!
定义了一个range对象,设置区域为一个单元格:就是一个单元格。调用replace函数的时候,发现替换的不仅是这个区域的(即一个单元格),而是整个工作表,我就很奇怪了,查了MSDN,列出如下:

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

Name Required/Optional Data Type Description 
What Required Variant The string you want Microsoft Excel to search for. 
Replacement Required Variant The replacement string. 
LookAt Optional Variant Can be one of the following XlLookAt constants: xlWhole or xlPart. 
SearchOrder Optional Variant Can be one of the following XlSearchOrder constants: xlByRows or xlByColumns. 
MatchCase Optional Variant True to make the search case sensitive. 
MatchByte Optional Variant 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 Variant The search format for the method. 
ReplaceFormat Optional Variant The replace format for the method. 

Return Value
Boolean


请给位大侠给出指点



[解决办法]
replace有两种,一种是方法,一种是函数,英文的意思是replace方法

单元格的替换应该是这样 [a1] = Replace([a1], 2, 3)
[解决办法]
估计是你的代码没写对,你录制一个替换的宏,看看代码和你的一样吗。

例子:将单元格A1内容中的 "A" 替换为 "B":
Range("A1").Replace What:="A", Replacement:="B", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

热点排行