On Cell change event vba

[Closed]
Report
Posts
1
Registration date
Monday October 19, 2015
Status
Member
Last seen
October 19, 2015
-
Posts
2779
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
July 29, 2021
-
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

1 reply

Posts
2779
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
July 29, 2021
468
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

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!