0

I want VBA to ignore "Worksheet_Change Function" when I just double click and exit the cell without any changes to cell value.

P.S. I've bellow code in Worksheet_Change to compare cell value to its previous value:

vNew = Range("cellChanged").value
Application.EnableEvents = False
Application.Undo
vOld = Range("cellChanged").value
Range("cellChanged").value = vNew
Application.EnableEvents = True 

But in my VBA code, changing value of a cell leads to change in another cells. So, this code runs nested until I got error on Application.Undo.

Appreciate any help.

Afshin Davoudy
  • 43
  • 2
  • 11
  • Side note - if you hit Escape, nothing should happen. But [this](https://stackoverflow.com/questions/4668410/how-do-i-get-the-old-value-of-a-changed-cell-in-excel-vba) should be helpful to compare the cell's current value to its "old" value and only proceed if there's been a change. – BigBen Feb 27 '20 at 13:30
  • @BigBen I've added some comment to my question. please check! – Afshin Davoudy Feb 27 '20 at 22:06
  • I wouldn't use `Application.Undo` here to be honest. I would use a selection change event as shown in the link I mentioned earlier. – BigBen Feb 28 '20 at 12:48
  • I missed the link. Thank you! – Afshin Davoudy Feb 29 '20 at 06:52

0 Answers0