Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Formula does not calculate | Excel Discussion (Misc queries) | |||
Formula to calculate 401(k) | Excel Worksheet Functions | |||
My formula won't calculate | Excel Discussion (Misc queries) | |||
sum formula does not calculate | Excel Discussion (Misc queries) | |||
Formula will not calculate | Excel Discussion (Misc queries) |