On Cell change event vba

Closed
ar14 Posts 1 Registration date Monday October 19, 2015 Status Member Last seen October 19, 2015 - Oct 19, 2015 at 06:34 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Oct 19, 2015 at 11:53 AM
Hello Folks,

I m trying to get hold of on cell change event vba code, if the cell value is changed to blank or zero. otherwise i have code which triggers if the cell value is updated to either more than or less than zero.
I understand that excel by default assumes blank cells to be zero but as part of a task i need to capture if the cell, if value is changed to zero or blank.

Your quick reply is appreciated.

Thanks
Related:

1 response

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 552
Oct 19, 2015 at 11:53 AM
Hi Ar14,

A blank/empty cell is not the same as zero/0.

May the code below guide you. First clear the cell (A1) and run the code, then put a zero in the cell and run the code again and you will see.

Sub RunMe()
If Range("A1") = vbNullString Then Range("A1").Value = "Cell was blank"
If Range("A1") = 0 Then Range(" A1").Value = "Cell contained a zero"
End Sub


Best regards,
Trowa
0