0

I have a spreadsheet with values in multiple columns “A:Z” I want to find and replace values in Column "B" depending on the value in column "B" and column "C". For example:

If Column B = SWI and Column C = IN then replace SWI with Switch Subscription

But if Column B = SWI and Column C = OUT then replace SWI with Switch Redemption

The table looks like that:

Col B       Col C
RED         OUT
RED         OUT
SWI         IN
SWI         OUT
SWI         IN
SWI         OUT
SUB         IN

I tried to write the code but it didn't work! Where is the problem?

N = Cells(Rows.Count, 1).End(xlUp).Row
    For i = 1 To N
        v1 = Cells(i, 2).Value
        v3 = Cells(i, 3).Value
        If v1 = "SWI" And v3 = "IN" Then Cells(i, 2).Value = "Switch Subscription"
        If v1 = "SWI" And v3 = "OUT" Then Cells(i, 2).Value = "Switch Redemption"
    Next i
help-info.de
  • 6,695
  • 16
  • 39
  • 41
shinpencil
  • 43
  • 1
  • 2
  • 9

2 Answers2

0

try with below code

    N = Cells(Rows.Count, "B").End(xlUp).Row
    For i = 1 To N
        v1 = Cells(i, 2).Value
        v3 = Cells(i, 3).Value
        If v1 = "SWI" And v3 = "IN" Then Cells(i, 2).Value = "Switch Subscription"
        If v1 = "SWI" And v3 = "OUT" Then Cells(i, 2).Value = "Switch Redemption"
    Next i
Karthick Gunasekaran
  • 2,697
  • 1
  • 15
  • 25
0

You have two if statements but never added End If Try this

If v1 = "SWI" And v3 = "IN" Then Cells(i, 2).Value = "Switch Subscription"
ElseIf v1 = "SWI" And v3 = "OUT" Then Cells(i, 2).Value = "Switch Redemption"
End If
BerticusMaximus
  • 705
  • 5
  • 16