I have some code that I currently use where if cell A changes, then cell B adjusts accordingly. If cell A is cleared, then cell B is cleared too.
Here is the code:
Works great!
However, I need to use something similar for a different project. So I adjusted the code as needed. But now, when the contents of cell A are cleared, cell B does not clear out. I have tried a few different approaches and I don't seem to get the correct results.
What is wrong with my code?
I also tried this, but to no avail:
Any thoughts? I bet it is something very obvious!! hahahah lol
-Spydey
P.S. I noticed that with my original code, I could paste the PASS or FAIL into the cells, and the dates would change, as needed. However, with pasting the numbers into this new project, the date doesn't change. For this new project, the value in column 5 will always be numeric (always numbers).
Here is the code:
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Count = 1 And Target.Column = 7 Then
If UCase(Target.Value) = "PASS" Or UCase(Target.Value) = "FAIL" Then
Target.Offset(0, 1) = Date
Else
Target.Offset(0, 1).ClearContents
End If
End If
End Sub
Works great!
However, I need to use something similar for a different project. So I adjusted the code as needed. But now, when the contents of cell A are cleared, cell B does not clear out. I have tried a few different approaches and I don't seem to get the correct results.
What is wrong with my code?
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Count = 1 And Target.Column = 5 Then
If IsNumeric(Target.Value) = True Then
Target.Offset(0, -3) = Date
Else
Target.Offset(0, -3).ClearContents
End If
End If
End Sub
I also tried this, but to no avail:
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Count = 1 And Target.Column = 5 Then
If IsNumeric(Target.Value) = True Then
Target.Offset(0, -3) = Date
ElseIf IsEmpty(Target.Value) = True Then
Target.Offset(0, -3).ClearContents
End If
End If
End Sub
Any thoughts? I bet it is something very obvious!! hahahah lol
-Spydey
P.S. I noticed that with my original code, I could paste the PASS or FAIL into the cells, and the dates would change, as needed. However, with pasting the numbers into this new project, the date doesn't change. For this new project, the value in column 5 will always be numeric (always numbers).
Last edited: