Vikrantnag
Vikrantnag

Reputation: 3

VBA help needed for if then statement

I have a VBA problem. I want to write a If statement where i want to say if A>=B, then 0 else B-A in a new column. and i want to repeat this till last row. Can anyone help me on this

Upvotes: 0

Views: 39

Answers (1)

Gary's Student
Gary's Student

Reputation: 96753

How about:

Sub qwerty()
    Dim N As Long, r As Range

    N = Cells(Rows.Count, "A").End(xlUp).Row
    Set r = Range("C1:C" & N)
    r.Formula = "=IF(A1>=B1,0,B1-A1)"
End Sub

enter image description here

Upvotes: 1

Related Questions