If statement does not recognize empty cell.

D

Dustin I

Thanks Peter for help with my previous post.

Ok, I have this code below, however it doesn't seem to
recognize when there is an empty cell. I have tried
using cell <> "" and I get the same result. It seems to
think there is something in the cell. I only want the
code to execute if it finds a value in xCell. I have
also tried Val(cellref).text <>.

Any suggestion?

' Declarations
Dim qty As Cell
Dim prc As Cell
Dim extPrc As Cell
Dim ttl As Long
Dim tbl As Table
' Initialization
Set tbl = ActiveDocument.Tables(2)

For i = 2 To tbl.Rows.Count
Set qty = tbl.Cell(Row:=i, Column:=2)
Set prc = tbl.Cell(Row:=i, Column:=4)
Set extPrc = tbl.Cell(Row:=i, Column:=5)

If Val(prc.Range.Text) <> Null Then
ttl = Val(qty.Range.Text) * Val(prc.Range.Text)
extPrc.Range.Text = ttl
Else
extPrc.Range.Text = ""
End If

Next
 
J

Jezebel

An empty cell actually contains two characters: vbcr + chr(7). The simple
test for whether a cell is empty is

If len(xCell.range.text) > 2 then .... xCell is not empty
 
G

Guest

Thanks!
-----Original Message-----
An empty cell actually contains two characters: vbcr + chr(7). The simple
test for whether a cell is empty is

If len(xCell.range.text) > 2 then .... xCell is not empty








.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top