I am trying to skip records which either have a zero as the value or is empty. As of now, i have the following code that checks for both explicitly, but I feel that the second check is redundant. But I want to confirm that I am right so that I can remove the second part of the IF
IF (CellInValue(RowInCrnt, ColInCrnt) = 0 Or CellInValue(RowInCrnt, ColInCrnt) = "") Then
No, "" is not equal to 0 and will produce a type mismatch in a strongly typed scenario, or won't come out as equal if used as Variant.
When the cell is empty, it's also not the same as zero, but it will come out as same, because in VB, Empty = 0 gives True because of implicit conversion happening in the background.
Same for Empty = "", will also give True for the same reason.
So you need both checks.
GSerg is completely correct.
If you really wanted to avoid doing 2 different checks, you could change your If to something like this:
If Clng(0 & CellInValue(RowInCrnt, ColInCrnt)) = 0 then
This returns true when CellInValue(RowInCrnt, ColInCrnt) is "", Empty, or 0.
Though if your function could return letters instead of numbers, this will have a type mismatch error in that case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With