[EXCEL] Question about handling multiple cell changes in a worksheet_change sub
Hello guys, so I have some code in a worksheet_change sub that works as I want it to when the user is editing a single cell at a time, but not when editing multiple cells across different rows. Here is the relevant code:
Private Sub Worksheet_Change(ByVal Target As Range) Application.EnableEvents = False If Not Intersect(Target, Range("M:M")) Is Nothing Then If Target.Offset(, 1).Value = "" Then If Not Target.Value = "" Then Target.Offset(, 1).Value = "In Transit" End If End If End If Application.EnableEvents = True End Sub
So the problem I have is when, for example, the user edits a single cell, such as M2, the code works properly and edits n2 if the conditions are met. But when the user selects a range of cells, such as the range M2 - N7, and hits delete, the code won't work as I want, and instead overwrites column O which shouldn't happen. I guess the problem is that "Target" refers to the entire range and not just the first column in that range, is there a way I can modify this code so that it only considers changes to cells in column M and only modifies column N on the same row in response to those changes? Or alternatively, is there a way that I can have this code not apply when a range of more than 1 cell is modified? It doesn't really need to run if the user is just deleting stuff, which is the only time the user will be modifying multiple cells at once.
Thanks for any help.