I have code that prevents changes to more than one cell at once. It will however allow for more than one cell to be deleted at a time. Below is the code that I am using and it works well.
Dim vClear As Variant
Dim vData As Variant
'This prevents more than one cell from being changed at once.
'If more than one cell is changed then validation checks will not work.
If Target.Cells.Count > 1 Then
vData = Target.Formula
For Each vClear In vData
If vClear <> "" Then 'If data is only deleted then more than one cell can be changed.
MsgBox "Change only one cell at a time", , "Too Many Changes!"
Application.Undo
Exit For
End If
Next
End If
What I am trying to add to it is when data is deleted I want it to check which columns data is being deleted from. If any of the columns meet the requirement, then I need the data in the equivalent row in another column to be deleted as well.
Here is an example of what I am trying to do. There are 2 columns that I need checked, they are G & H. If the data is deleted from either of these 2 columns then I want column I to be deleted as well. Let’s say I select the range of D5:G10 and delete the contents from it. Since column G is one of the requirements I would want I5:I10 deleted as well. If I was to delete D5:F10 then it would not delete anything in column I since neither columns G or H were selected.
Below is an example code of what I am trying to do. I know it is impossible for my code below to work, this is just a brief summary of what I am trying to do, I can’t figure out how to get the variant to also check the column as well. Please let me know if someone knows how to do this.
Dim vClear As Variant
Dim vData As Variant
'This prevents more than one cell from being changed at once.
'If more than one cell is changed then validation checks will not work.
If Target.Cells.Count > 1 Then
vData = Target.Formula
For Each vClear In vData
If vClear <> "" Then 'If data is only deleted then more than one cell can be changed.
MsgBox "Change only one cell at a time", , "Too Many Changes!"
Application.Undo
Exit For
Else
If vClear = "" Then
If vClear.Column = 7 Or vClear.Column = 8 Then
ActiveSheet.Cells(vClear.Row, 9) = ""
End If
End If
End If
Next
End If