=IF(AX6="CANCELLED",0,"")
Why VBA?
Why not just put formula:
in cell AZ6, and then copy that formula all the way down to row 1000?Code:=IF(AX6="CANCELLED",0,"")
If you want values and not the formula, you can do a Copy -> Paste Special -> Values afterwards.
Recording doing the steps above manually using the Macro Recorder would also give you the VBA code to do that.
The devil is often in the details not mentioned!I am sorry I did not mention that in column AZ rows 6 through 1000 there is a number value in it
Sub MyMacro()
Dim rng As Range
Dim cell As Range
Application.ScreenUpdating = False
' Designate range to check
Set rng = Range("AX6:AX1000")
' Loop through range
For Each cell In rng
' Check to see if cell equals "CANCELLED"
If cell.Value = "CANCELLED" Then
' Zero out column AZ
cell.Offset(0, 2).Value = 0
End If
Next cell
Application.ScreenUpdating = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("AX6:AX1000")) Is Nothing Then
If Target = "CANCELLED" Then
Application.EnableEvents = False
Target.Offset(0, 2) = 0
Application.EnableEvents = True
End If
End If
End Sub