Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Naz Naz is offline
external usenet poster
 
Posts: 85
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 180
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



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
Formula does not calculate ggrott Excel Discussion (Misc queries) 4 July 1st 08 02:19 PM
Formula to calculate 401(k) carmelcorn45 Excel Worksheet Functions 1 November 2nd 06 04:26 PM
My formula won't calculate Lollycat Excel Discussion (Misc queries) 3 August 13th 05 03:23 PM
sum formula does not calculate Dena X Excel Discussion (Misc queries) 3 July 19th 05 01:34 PM
Formula will not calculate Excel User Excel Discussion (Misc queries) 1 February 10th 05 08:33 PM


All times are GMT +1. The time now is 02:58 AM.

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

About Us

"It's about Microsoft Excel"