【发布时间】:2013-07-15 01:59:58
【问题描述】:
我有这段代码,它工作正常。现在我需要改变它,我不知道怎么做。
整个 wordksheet 中的代码搜索。我只需要搜索 1 列
代码搜索整个单元格。我需要在单元格的左侧、中间或右侧进行搜索。
Sub ChgInfo()
Dim WS As Worksheet
Dim Search As String
Dim Replacement As String
Dim Prompt As String
Dim Title As String
Dim MatchCase As Boolean
Prompt = "What is the original value you want to replace?"
Title = "Search Value Input"
Search = InputBox(Prompt, Title)
Prompt = "What is the replacement value?"
Title = "Search Value Input"
Replacement = InputBox(Prompt, Title)
For Each WS In Worksheets
WS.Cells.Replace What:=Search, Replacement:=Replacement, _
LookAt:=xlPart, MatchCase:=False
Next
End Sub
【问题讨论】:
-
“代码搜索整个单元格。我需要搜索单元格的左侧或中间或右侧。”是什么意思?
-
WS.Columns(1).Replace What:=Search, Replacement:=Replacement, LookAt:=xlPart, MatchCase:=False似乎您的代码已经替换了部分单元格内容,而不仅仅是整个文本。除非您所说的“左侧或中间或右侧”是指其他意思