ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Calculate Formula (https://www.excelbanter.com/excel-programming/347810-calculate-formula.html)

Naz

Calculate Formula
 
Hi all,

I need to create a simple calculater in Excel for kids. I can create forms
and add a box to enter the calculation. But how do i get Excel to evaluate
the contents of the box and show the answer?

I have a text box called box1 where the user enters the calc (1+2, 24/5 so on)
and then a label on the form called answer.
I thought that Answer=Box1 would work but it just give a duplicate of the
calc entered.

I know i should be able to do this but i just can't figure it.

All help is appreciated



--

_______________________
Naz,
London

bpeltzer

Calculate Formula
 
You need to do something to get the input string evaluated. Something like
the following (some error checking would be nice, but I'll leave that for
you;-) ):

Dim result As Double
ActiveSheet.Shapes("Answer").Select
result = Evaluate(Box1)
Selection.Characters.Text = Box1 & " = " & result

HTH. --Bruce

"Naz" wrote:

Hi all,

I need to create a simple calculater in Excel for kids. I can create forms
and add a box to enter the calculation. But how do i get Excel to evaluate
the contents of the box and show the answer?

I have a text box called box1 where the user enters the calc (1+2, 24/5 so on)
and then a label on the form called answer.
I thought that Answer=Box1 would work but it just give a duplicate of the
calc entered.

I know i should be able to do this but i just can't figure it.

All help is appreciated



--

_______________________
Naz,
London


Leith Ross[_371_]

Calculate Formula
 

Hello Naz,

When say form, I am assuming you mean a VBA UserForm with a TexBox and
Label on it. Take the equation from the TextBox and use it as a cell
formula on the worksheet. Excel can parse the equation and calculate
the result. Take the cell result and make it the Label Caption.

EXAMPLE:

Calc = TextBox1.Text
Worksheets("Sheet1").Range("A1").Formula = "=" & Calc
Label1.Caption = Worksheets("Sheet1").Range("A1").Value

Just change the worksheet name ("Sheet1") to and the cell ("A1") tp
whatever you are using.

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=492427


Tom Ogilvy

Calculate Formula
 
Dim Calc as String
Calc = TextBox1.Text
Label1.Caption = Evaluate(Calc)

would eliminate the trip through the worksheet.

--
Regards,
Tom Ogilvy



"Leith Ross" wrote
in message ...

Hello Naz,

When say form, I am assuming you mean a VBA UserForm with a TexBox and
Label on it. Take the equation from the TextBox and use it as a cell
formula on the worksheet. Excel can parse the equation and calculate
the result. Take the cell result and make it the Label Caption.

EXAMPLE:

Calc = TextBox1.Text
Worksheets("Sheet1").Range("A1").Formula = "=" & Calc
Label1.Caption = Worksheets("Sheet1").Range("A1").Value

Just change the worksheet name ("Sheet1") to and the cell ("A1") tp
whatever you are using.

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile:

http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=492427





All times are GMT +1. The time now is 10:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com