user2258740
user2258740

Reputation: 309

Can I modify this macro to run just on one column?

I'm using this to find and replace values, and it works fine for the entire sheet I have open:

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

I'd like to edit it so that I runs just on Column U--instead of the full sheet.

I've seen other folks try to solve this using lines like Set rng = Range("U:U") but I'm not sure where to add that in the code above or if this is the best approach.

If anyone has a suggestion, I'd appreciate it.

Upvotes: 1

Views: 42

Answers (1)

urdearboy
urdearboy

Reputation: 14590

 Range("U:U").Replace What:=wTxt, Replacement:=rTxt, LookAt:=xlPart

Upvotes: 2

Related Questions