我可以修改此宏以仅在一列上运行吗?

问题描述 投票:1回答:1

我正在使用它来查找和替换值,它对我打开的整个工作表工作正常:

Sub replaceStringInCells()
Dim wTxt As String
Dim rTxt As String
Dim rNum As Integer
rNum = 0
For Each Row In Range("swapvalues").Rows  '<== change the wordlist Name here as required
    wTxt = Row.Cells(1).Value
    rTxt = Row.Cells(2).Value
        Selection.Replace What:=wTxt, Replacement:=rTxt, LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
            rNum = rNum + 1
Next
End Sub

我想编辑它,以便我只在列U上运行 - 而不是整张表。

我见过其他人尝试使用像Set rng = Range("U:U")这样的行解决这个问题,但我不确定在上面的代码中添加它的位置,或者这是最好的方法。

如果有人有建议,我会很感激。

excel vba
1个回答
2
投票
 Range("U:U").Replace What:=wTxt, Replacement:=rTxt, LookAt:=xlPart
© www.soinside.com 2019 - 2024. All rights reserved.