Sum that ignores text

S

Smurfette18

Hi,

I am trying to do a simple sum using inputs taken from userform
comboboxes. The problem is that the inputs can contain the text
character "-", and this is causing an error. I have tried converting
the inputs to values using val, cval, cdec, etc, but I think that the
problem is that the application.sum function in VBA, like the simple
operation "+", can't handle text. Any ideas about how to deal with
this?

Thanks!
-Tim
 
J

JE McGimpsey

The Worksheet function SUM() (which you call as Application.Sum) does
handle text by ignoring it. But you said you're converting the inputs to
(numeric) values. Does that not work?

Perhaps some examples of what you're doing would help to clarify the
problem...
 
D

Dave Peterson

=sum() adds numbers.

Strings like: 1234+34-3465-2345+(1234/2143)
aren't numbers

But maybe you could use application.evaluate() to evaluate a string that looks
like a formula.
 
B

Bob Phillips

MsgBox Val(TextBox1.Text) + Val(TextBox2.Text)

works for me

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
D

Dave Peterson

I got the impression that the OP was getting formula like strings in the
textboxes in a userform. If my guess is correct, then I don't think this is
better.

And if the values in that range are really strings that look like:
1234+345+234
Then I don't think =sum() or =sumproduct() will help.
 

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