Consulting

Results 1 to 5 of 5

Thread: Solved: Test for Empty Cell in a Table

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Tutor jamescol's Avatar
    Joined
    May 2004
    Location
    Charlotte, NC
    Posts
    251
    Location

    Solved: Test for Empty Cell in a Table

    OK, I need some validation of my thought. I'm testing to see if a cell in a table is blank. Using:

    [vba]
    If ActiveDocument.Tables(3).Cell(lRows, 1).Range.Text = ""
    [/vba]

    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
    [vba]
    If Len(ActiveDocument.Tables(3).Cell(lRows, 1).Range.Text -2) = 0
    [/vba]

    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
    "All that's necessary for evil to triumph is for good men to do nothing."

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Hi James,

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

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

    (Looking forward to a real answer. )

  3. #3
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    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  .

  4. #4
    VBAX Tutor jamescol's Avatar
    Joined
    May 2004
    Location
    Charlotte, NC
    Posts
    251
    Location
    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 :
    [vba]
    If Len(ActiveDocument.Tables(1).Cell(lRows, 1).Range.Text) = 2
    [/vba]

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

    Cheers,
    James
    "All that's necessary for evil to triumph is for good men to do nothing."

  5. #5
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You're Welcome

    P.S.

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •