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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
If you remove c.Value <> Empty then the if statement is true. Looks like the 0 is being seen as empty.
 
Upvote 0
What do you mean by 'ignoring'?
 
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,213,564
Messages
6,114,334
Members
448,567
Latest member
Kuldeep90

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