Morning all! Happy Monday!
So the below code is working, with a caveat. Was hoping someone could review for me!
All cells in range J9:J4000 are blank. If a user types anything into any of the cells in this range, the code will delete any content in the cell to the left of it, and place "Custom Message" two cells to the left of it. This works perfectly, and as intended.
The issue I'm running into is this: If a user deletes what they entered into a cell in J9:J4000, (or even just presses delete in any cell in this range) the code still runs and makes the changes. This is not the intent.
I only need the code to run when someone type something in J9:J4000. If they delete what they typed in, it would be nice to also clear out "Custom Message" but not required.
Thoughts on how to alter the code to accomplish? To be fair, this was code I patched together, and despite doing research, I don't fully understand this line: "If Not rng Is Nothing Then" which I assume is the crux of the issue. if someone could explain it better than what I'm finding online, I'd appreciate it!
Thanks all!
So the below code is working, with a caveat. Was hoping someone could review for me!
All cells in range J9:J4000 are blank. If a user types anything into any of the cells in this range, the code will delete any content in the cell to the left of it, and place "Custom Message" two cells to the left of it. This works perfectly, and as intended.
The issue I'm running into is this: If a user deletes what they entered into a cell in J9:J4000, (or even just presses delete in any cell in this range) the code still runs and makes the changes. This is not the intent.
I only need the code to run when someone type something in J9:J4000. If they delete what they typed in, it would be nice to also clear out "Custom Message" but not required.
Thoughts on how to alter the code to accomplish? To be fair, this was code I patched together, and despite doing research, I don't fully understand this line: "If Not rng Is Nothing Then" which I assume is the crux of the issue. if someone could explain it better than what I'm finding online, I'd appreciate it!
Thanks all!
VBA Code:
Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Set rng = Intersect(Target, Me.Range("J9:J4000"))
If Not rng Is Nothing Then
On Error GoTo SafeExit
Application.EnableEvents = False
Dim cell As Range
For Each cell In rng
cell.Offset(, -1).Value = ("")
cell.Offset(, -2).Value = ("Custom Message")
Next
End If
SafeExit:
Application.EnableEvents = True
End Sub