Reputation: 3
I have a single excel worksheet. I want to replace text in column F IF both Column C has a particular text ("apple") and Column F has a particular number ("56"). I want the replacement value for the Cell in Column F to be "1".
To summarize, if c3=apple and f3=56, I want f3 to be changed to 1.
But if c3 is anything but apple or f3 anything but 56, I do not want anything changed.
The code I have currently is as follows:
Sub Macro3()
Dim x As Range
Dim y As Range
For Each x In Range("C2:C9999")
For Each y In Range("F2:F9999")
If x = "apple" And y = "56" Then y = "1"
Exit For
Next y
Next x
End Sub
Upvotes: 0
Views: 288
Reputation: 152450
Only need one loop:
Sub Macro3()
Dim y As Range
For Each y In Range("F2:F9999")
If y.offset(,-3) = "apple" And y = 56 Then y = 1
Next y
End Sub
Upvotes: 1