convert string to mathematical expression

N

Nateysz

Hello,

what's wrong with below code ?
I want to get result of equation.

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


firstnumber = InputBox("Please, give me first number")

secondnumber = InputBox("Please, give me second number")
Myoperator = InputBox("Please give me an operator, for example + or - ")
Myresult = Val(firstnumber) & Myoperator & Val(secondnumber)

wiersz = Range("A1").Row



Myresult = Val(Myresult)
Cells(wiersz, 1).Value = firstnumber
Cells(wiersz, 2).Value = Myoperator
Cells(wiersz, 3).Value = secondnumber
Cells(wiersz, 4).Value = "="
Cells(wiersz, 5).Value = Myresult
 
I

IanC

I'm not sure why your code doesn't work (perhaps someone else could explain
it), but either of the following lines will put a formula into Cells(wiersz,
5) instead of a value, giving you the displayed result you need.

Cells(wiersz, 5).Formula = "=" & Cells(wiersz, 1).Value & Myoperator &
Cells(wiersz, 3).Value
Cells(wiersz, 5).Formula = "=" & firstnumber & Myoperator & secondnumber

You don't need the 3 lines referring to Myresult.
 
N

norie

Can you tell us what problem(s) you are experiencing?

Do you want to put a formula in a cell or actually evaluate that
formula in the code?
 
N

Nateysz

W dniu 04.09.2010 16:28, norie pisze:
Can you tell us what problem(s) you are experiencing?

Do you want to put a formula in a cell or actually evaluate that
formula in the code?

I want to evaluate that formula, but as I tell, it's always only string
not equation which Excel should proceed
 

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