Why I get the error?

A

avkokin

Hello.
There is the variables V1 as Double and xC2 as string. I assignmenting
for it next expression:
xC2 = SourceTable.Rows(cmbFood1.ListIndex + 1).Cells(2).Range.Text
V1 = Left(xC2, Len(xC2) - 2)
V1 = CDbl(V1)
If the number of getting is not zero then all OK. But if the number
from cell of table is zero then I get the error "type mismatch".
Why and how can I recovery it? Thank you very much.
P.S. I can't use the function VAL because I have the numbers with
commas instead the numbers with dot (it's local).
 
D

Doug Robbins - Word MVP

Using the following:

Dim xC2 As Range
Dim V1 As Double
Set xC2 = ActiveDocument.Tables(1).Cell(1, 1).Range
xC2.End = xC2.End - 1
V1 = CDbl(xC2.Text)
MsgBox V1

as long as the entry in the Cell is numeric (0, 1.1 or 1,1) no error occurs.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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