tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,834
- Office Version
- 365
- 2019
- Platform
- Windows
My worksheet contains a headings row (cells A1 to C1) and 1 row of data (cells A2 to C2).
I want to prevent users from altering the headings, so I add this code:
If the user tries to alter any value in cells A1 to C1, the code reverses it.
If the user tries to type in any cell in row 1, eg D1 or E1, the code also reverse it, which is what I want.
However, if the range (A1 to C2) were converted into a table (by pressing Ctrl+T), things don't quite go according to plan.
If the user tries to alter any value in cells A1 to C1, the code reverses it, (as expected).
However, if the user tries to type in any cell in row 1, eg D1 or E1, Excel extends the table range to include this new cell address, then the code reverses this last action (the extending of the table).
Whatever value was entered still remains.
How can I change it so the value typed is reversed as well?
Thanks
I want to prevent users from altering the headings, so I add this code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 1 Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
End Sub
If the user tries to alter any value in cells A1 to C1, the code reverses it.
If the user tries to type in any cell in row 1, eg D1 or E1, the code also reverse it, which is what I want.
However, if the range (A1 to C2) were converted into a table (by pressing Ctrl+T), things don't quite go according to plan.
If the user tries to alter any value in cells A1 to C1, the code reverses it, (as expected).
However, if the user tries to type in any cell in row 1, eg D1 or E1, Excel extends the table range to include this new cell address, then the code reverses this last action (the extending of the table).
Whatever value was entered still remains.
How can I change it so the value typed is reversed as well?
Thanks