tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,915
- Office Version
- 365
- 2019
- Platform
- Windows
Let's assume I have the numbers 1,2,3 in cells A1 through to A3 and the numbers 2,3,4 in cells B1 through to D1.
This is the code to prevent changes to column A:
It works as expected if only a single cell is changed.
For example, if I attempt to change the value in cell A1 to say f, the code reverses the change and cell A1 shows the value of 1.
However, if I highight cells A1 and B1, then type something, say e and press Ctrl + Enter, the code reverses the action (and cell A1 shows 1 and cell B1 shows 2 as originally) but what I want is for cell A1 to show the value of 1 (because it's reversed the action) and cell B1 to show the newly entered value of e.
How can I amned my code to achieve this?
Thanks
This is the code to prevent changes to column A:
Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
For Each rng In Target.Cells
If rng.Column = 1 Then Call Reverse
Next rng
Set rng = Nothing
End Sub
Private Sub Reverse()
With Application
.EnableEvents = False
.Undo
.EnableEvents = True
End With
End Sub
It works as expected if only a single cell is changed.
For example, if I attempt to change the value in cell A1 to say f, the code reverses the change and cell A1 shows the value of 1.
However, if I highight cells A1 and B1, then type something, say e and press Ctrl + Enter, the code reverses the action (and cell A1 shows 1 and cell B1 shows 2 as originally) but what I want is for cell A1 to show the value of 1 (because it's reversed the action) and cell B1 to show the newly entered value of e.
How can I amned my code to achieve this?
Thanks