tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,924
- Office Version
- 365
- 2019
- Platform
- Windows
Can someone please try this and see if you get the same problem?
In a new workbook, put the number 1 into cell A1.
Then add a Data Validation rule, stating it must be a whole number greater than 0.
Now in the VB Editor, put this is Sheet1:
Put a break point in the first line of the code.
Now change the value in the Excel Sheet1 cell A1 from 1 to say 2. The Data Validation message pops up stating it's an invalid value, do you want to Retry or Cancel? Click Cancel.
The code will hit the break point. Step into it through to the end. The value in Sheet1 should return to 1, as expected.
However, if you attempt to put a letter, say a, in cell A1, the code again hits the break point but when you step into it, it goes to End Sub and when you press F8, it starts at the first line again!
Why is that?
Thanks
In a new workbook, put the number 1 into cell A1.
Then add a Data Validation rule, stating it must be a whole number greater than 0.
Now in the VB Editor, put this is Sheet1:
Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range) ' PUT BREAK POINT HERE.
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End Sub
Put a break point in the first line of the code.
Now change the value in the Excel Sheet1 cell A1 from 1 to say 2. The Data Validation message pops up stating it's an invalid value, do you want to Retry or Cancel? Click Cancel.
The code will hit the break point. Step into it through to the end. The value in Sheet1 should return to 1, as expected.
However, if you attempt to put a letter, say a, in cell A1, the code again hits the break point but when you step into it, it goes to End Sub and when you press F8, it starts at the first line again!
Why is that?
Thanks