dim a String A="2+3+5" A=cdbl(A)???

  • Thread starter Thread starter Andoni
  • Start date Start date
A

Andoni

If I have a string such as:

a="1+5+9+7"

and I want to use the number, non the string, I mean if I want to ge
the answer=22

a=cdbl(A) does not work!
How can I do this?

PS: I need this
 
Sure thing

Sub test()
Dim A As String, D As Double
A = "1+5+9+7"
D = Evaluate(A)
MsgBox D, , A
End Sub

HTH. Best wishes Harald
 
Could you please clarify a little more on how / where you
have this setup. Is the string in the code? Are you
attempting to get the result of the string into a cell?
More information will make it easier to determine what you
are attempting to do, and there by allow for better help.
Ascheman
 
Ok if I am understanding this right you want D to show the
value of A correct. If this is so then change 'D = Evaluate
(A)' to 'D = A'. Also since A is a string you might have
to setup 'A = "1+5+9+7"' like this 'A = Integer
("1+5+9+7")' to get it to do the math. If I am incorrect
in this then a little more explanation of what your
attempting would help. What are you trying to do with this
information? Is this being displayed via a cell, or
through the msgBox?
Ascheman
 
I copied the suggested code into a module and ran it. It
does what is requested. I am not sure why, but it works!
Help provides information but not much help on this.

I hope that helps!

Kevin
 
If I am incorrect
Just for benefit of the OP since you have obfuscated the correct solution
provided by Harald, nothing you have said so far is correct.

Harald's method worked fine (except for including the string A in the
msgbox). Your suggestions don't work at all.
 

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

Back
Top