+ Reply to Thread
Results 1 to 4 of 4

Calculate Formula

  1. #1
    Naz
    Guest

    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. #2
    bpeltzer
    Guest

    RE: 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. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    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

  4. #4
    Tom Ogilvy
    Guest

    Re: 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" <[email protected]> wrote
    in message news:[email protected]...
    >
    > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1