why does VBA this statement ignore 0 values - it shouldnt

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,302
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi All

Hoping you can help me understand why this is ignoring 0 values when it shouldnt - it is a number and ive tested it

If c.Value <> "" And c.Value <> Empty And c.Value <> "Ok" And c.Value <> "Not Ok" Then
'do something

Thank You
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
If you remove c.Value <> Empty then the if statement is true. Looks like the 0 is being seen as empty.
 
Upvote 0
Hi Norie - it was not including 0s a number and treating it as empty
 
Upvote 0
Code:
If c.Value <> "" And Not IsEmpty(c.Value) And c.Value <> "Ok" And c.Value <> "Not Ok" Then
 
Upvote 0
Hi SHG - thank you

ill give that a go - whats the difference between

Not IsEmpty(c.Value)

and

C.value <> empty
 
Upvote 0
VBA coerces 0 to Empty for comparison purposes. IsEmpty tests the Variant Type in the cell, which is always String, Boolean, Double, Error, or Empty.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top