Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Sum that ignores text

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Sum that ignores text

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...

In article om,
Smurfette18 wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Sum that ignores text

=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.



Smurfette18 wrote:

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


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Sum that ignores text

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)

"Smurfette18" wrote in message
ps.com...
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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Sum that ignores text

Sumproduct is smarter than sum. Try this function

=SUMPRODUCT((--VALUE(A1:A3)))

"Dave Peterson" wrote:

=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.



Smurfette18 wrote:

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


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Sum that ignores text

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.

Joel wrote:

Sumproduct is smarter than sum. Try this function

=SUMPRODUCT((--VALUE(A1:A3)))

"Dave Peterson" wrote:

=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.



Smurfette18 wrote:

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


--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Set rng for Column A only (ignores other columns) Aria[_2_] Excel Programming 4 September 10th 07 04:50 AM
Excel ignores "Text qualifiers" in Unicode files Doug Excel Discussion (Misc queries) 0 June 8th 06 09:30 PM
formula ignores last infor - please help sonar Excel Worksheet Functions 8 November 22nd 05 08:53 AM
How do you use text in a formula so it will calc, but ignores txt RLP Excel Discussion (Misc queries) 2 July 5th 05 10:15 PM
Min Value using array ignores Zero mauddib Excel Discussion (Misc queries) 2 February 16th 05 07:02 PM


All times are GMT +1. The time now is 05:21 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"