Home > Software design >  VBA If with two conditions
VBA If with two conditions

Time:02-11

I am trying to write a vba, which checks if column A is a specific string and column B is a specific string. If it's true, the cell in Column B should change its value to the string from column A. I think I am far away from the correct code. Any help?

Sub NomenklaturDatum()

Dim cell As Range
Dim rng As Range

For Each cell In rng

if cell.Value in rng("J5:J175") = "2019" and cell.Value in rng("D5:D175") = ("Backlog") Then
cell.Value in rng("J5:J175") = "Backlog"

End If
Next
End Sub

CodePudding user response:

Something within these lines

Sub NomenklaturDatum()

    Dim cl As Range

    For Each cl In Range("J5:J175")
        If cl.Offset(0, -6).Value = "Backlog" And cl.Value = "2019" Then
            cl.Value = "Backlog"
        End If
    Next
    
End Sub

Of course, you can make it more versatile - pass range as argument, or detect the last row, etc.

  • Related