Link to home
Create AccountLog in
Avatar of BlairBrenner
BlairBrennerFlag for United States of America

asked on

Visual Basic Excel - value of cell with 0 evaluates to same value with cell that is blank

I am comparing values in cells of two work sheets.  The sheets are supposed to contain the same values.  

If a cell in one sheet does not correspond to the cell in the other sheet, then the program displays the unequal cells and stops.

If cell a1 in sheet1 has a value of 0 (zero) and cell a1 in sheet2 is blank, the following statement evaluates as false:
If (Worksheets("Sheet1").Cells(X, Y).Value <> Worksheets("Sheet2").Cells(X, Y).Value) Then

In other words, the statements after "Then" are skipped and the program checks the next pair of cells.

How can I get VB to realize 0 and blank are <>??

Thanks
Avatar of sentner
sentner
Flag of United States of America image

If you use the "text" property instead of the "value" property, I believe it should list them as 0 and "" thus should be non-equal.  
Avatar of BlairBrenner

ASKER

When I change the property to "text", cells with numbers are flagged as not equal, when they are.

Other ideas?

Thanks
Hmm.. I tested, and it worked properly for me.  Are those numbers perhaps formatted/displayed differently?
ASKER CERTIFIED SOLUTION
Avatar of lemonadesoda
lemonadesoda

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Avatar of Chris Raisin
Chris Raisin
Flag of Australia image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account