I am relatively new to VBA.
Below is my code that works on just row 2.
Option Explicit
Public precedent
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.[D2]) Is Nothing Then
If Me.precedent <> Me.[D2].Value Then
Me.[F2] = ""
Me.[H2] = ""
Me.precedent = Me.[D2].Value
End If
End If
End Sub
I would like this code to run on every row except row 1 as this is my header.
How do I do this? Would I use a loop?
It shouldn't be so complicated. Just check Target.Row and Target.Column. If the former is greater than 1 and the latter is equal to 4, trigger whatever action you want.
Modify the following code accordingly.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row > 1 And Target.Column = 4 Then
Range("F" & Target.Row) = vbNullString
Range("H" & Target.Row) = vbNullString
End If
End Sub
Let us know if this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With