PDA

View Full Version : Solved: Test for Empty Cell in a Table



jamescol
07-11-2004, 11:51 PM
OK, I need some validation of my thought. I'm testing to see if a cell in a table is blank. Using:


If ActiveDocument.Tables(3).Cell(lRows, 1).Range.Text = ""


doesn't work when the cell is blank. The code always run the IF statement. So I checked the Len of the cell, and see that it is 2 when the cell is blank. I assume there is some sort of hidden formatting code in the cell.

So should I check the cell's length? Like

If Len(ActiveDocument.Tables(3).Cell(lRows, 1).Range.Text -2) = 0


Or is there a better method?

Oh yeah, and does anyone know what the 2 hidden characters/codes in the cell are? Curious

Thanks,
James

Zack Barresse
07-12-2004, 12:46 AM
Hi James,

Not too sure about any solution, but I'd change the syntax of your second code string by moving a paren...

If Len(ActiveDocument.Tables(1).Cell(lRows, 1).Range.Text) - 2 = 0

(Looking forward to a real answer. :) )

Jacob Hilderbrand
07-12-2004, 01:00 AM
firefytr's code is correct and will return a True if the cell is blank. Just note that his code has Tables(1), and yours is Tables(3), so modify as needed.

The first hidden character is Chr(13) and is a carriage return.
The second hidden character is Chr(7) and is a the non-printing character that looks like a square  .

jamescol
07-12-2004, 01:23 AM
Thanks again Jacob! Guess those codes are needed because of the table/cell structure. What a pain, and unless I missed it, not documented in the Help file.

Zack, I actually changed the code to :

If Len(ActiveDocument.Tables(1).Cell(lRows, 1).Range.Text) = 2


Figured the change would save a cycle - every "bit" helps :)

Cheers,
James

Jacob Hilderbrand
07-12-2004, 01:37 AM
You're Welcome

P.S.

Well we all know how thorough MS was with the help files. ;)