BillySilly
New Member
- Joined
- Jan 23, 2013
- Messages
- 49
Hi
I have a cell L5 validated for a Date and the following code comes into play if the cell contents is changed.
On the sheet code page
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$L$5" Then Call Change
End Sub
On a regular module
Code:
Sub Change()
MsgBox "Hello" ‘code will be something useful
End Sub
If I select the cell and start to change it by clicking in the formula bar I get the OK tick and Cancel X on the formula bar.
If without changing it I click the OK tick or if I click on the Cancel X it leaves the cell unchanged and Change is not called….fine
If I enter a valid date and click the OK tick Change is called…. fine
If I enter an invalid date and click the OK tick it returns the validation Msg Box with buttons for Retry and Cancel but puts the invalid date in L5. When I do enter a valid date Change is called…..fine
If I click Cancel in the Msg box or Cancel (X) in the formula bar it reverts to the original L5 contents which triggers Change….infine
How do I modify the code so that neither of the Cancels will trigger Change?
I have a cell L5 validated for a Date and the following code comes into play if the cell contents is changed.
On the sheet code page
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$L$5" Then Call Change
End Sub
On a regular module
Code:
Sub Change()
MsgBox "Hello" ‘code will be something useful
End Sub
If I select the cell and start to change it by clicking in the formula bar I get the OK tick and Cancel X on the formula bar.
If without changing it I click the OK tick or if I click on the Cancel X it leaves the cell unchanged and Change is not called….fine
If I enter a valid date and click the OK tick Change is called…. fine
If I enter an invalid date and click the OK tick it returns the validation Msg Box with buttons for Retry and Cancel but puts the invalid date in L5. When I do enter a valid date Change is called…..fine
If I click Cancel in the Msg box or Cancel (X) in the formula bar it reverts to the original L5 contents which triggers Change….infine
How do I modify the code so that neither of the Cancels will trigger Change?