+ Reply to Thread
Results 1 to 6 of 6

multiply two numbers and show the answer in a textbox

  1. #1
    gem
    Guest

    multiply two numbers and show the answer in a textbox

    i need to multiply two numbers from two different text boxes then show the
    answer in another text box, this is on an excel userform!
    Can anyone help?
    thanks

  2. #2
    Nick Hodge
    Guest

    Re: multiply two numbers and show the answer in a textbox

    Gem

    It depends if you are using a button to trigger the update, if not, you
    could use something like the textbox_afterupdate event like so (This is very
    basic code with little error checking. It uses three text boxes TextBox1
    and 2 have the numbers in and 3 shows the result)

    Private Sub TextBox1_AfterUpdate()
    If TextBox2.Value = "" Then Exit Sub
    TextBox3.Value = TextBox1.Value * TextBox2.Value
    End Sub

    Private Sub TextBox2_AfterUpdate()
    If TextBox1.Value = "" Then Exit Sub
    TextBox3.Value = TextBox1.Value * TextBox2.Value
    End Sub

    --
    HTH
    Nick Hodge
    Microsoft MVP - Excel
    Southampton, England
    www.nickhodge.co.uk
    [email protected]HIS


    "gem" <[email protected]> wrote in message
    news:[email protected]...
    >i need to multiply two numbers from two different text boxes then show the
    > answer in another text box, this is on an excel userform!
    > Can anyone help?
    > thanks




  3. #3
    JLatham
    Guest

    RE: multiply two numbers and show the answer in a textbox

    You could also try these - basically says that after typing something into
    one of the text boxes, verify that both text boxes contain numeric
    information and if they do, then multiply them and put the result in a label
    as its caption.

    I chose the Label instead of a text box because it's more difficult for the
    user to accidentally alter what's displayed on one of them. But text box
    would work just like in Nick Hodge's suggestion.

    Here's code:

    Private Sub txt_Num1_AfterUpdate()

    If IsNumeric(Me!txt_Num1) And IsNumeric(Me!txt_Num2) Then
    Me!lbl_Result.Caption = Me!txt_Num1 * Me!txt_Num2
    End If

    End Sub

    Private Sub txt_Num2_AfterUpdate()
    If IsNumeric(Me!txt_Num1) And IsNumeric(Me!txt_Num2) Then
    Me!lbl_Result.Caption = Me!txt_Num1 * Me!txt_Num2
    End If
    End Sub



    "gem" wrote:

    > i need to multiply two numbers from two different text boxes then show the
    > answer in another text box, this is on an excel userform!
    > Can anyone help?
    > thanks


  4. #4
    gem
    Guest

    Re: multiply two numbers and show the answer in a textbox

    ok i have typed this in the code for the text boxes. do i have to link it to
    a cell on the worksheet? as nothing is happening!!!

    "Nick Hodge" wrote:

    > Gem
    >
    > It depends if you are using a button to trigger the update, if not, you
    > could use something like the textbox_afterupdate event like so (This is very
    > basic code with little error checking. It uses three text boxes TextBox1
    > and 2 have the numbers in and 3 shows the result)
    >
    > Private Sub TextBox1_AfterUpdate()
    > If TextBox2.Value = "" Then Exit Sub
    > TextBox3.Value = TextBox1.Value * TextBox2.Value
    > End Sub
    >
    > Private Sub TextBox2_AfterUpdate()
    > If TextBox1.Value = "" Then Exit Sub
    > TextBox3.Value = TextBox1.Value * TextBox2.Value
    > End Sub
    >
    > --
    > HTH
    > Nick Hodge
    > Microsoft MVP - Excel
    > Southampton, England
    > www.nickhodge.co.uk
    > [email protected]HIS
    >
    >
    > "gem" <[email protected]> wrote in message
    > news:[email protected]...
    > >i need to multiply two numbers from two different text boxes then show the
    > > answer in another text box, this is on an excel userform!
    > > Can anyone help?
    > > thanks

    >
    >
    >


  5. #5
    gem
    Guest

    RE: multiply two numbers and show the answer in a textbox

    Thanks JLatham. it worked!!!
    one more thing though. there is only one digit after the decimal point,how
    do i change that in the properties?


    "JLatham" wrote:

    > You could also try these - basically says that after typing something into
    > one of the text boxes, verify that both text boxes contain numeric
    > information and if they do, then multiply them and put the result in a label
    > as its caption.
    >
    > I chose the Label instead of a text box because it's more difficult for the
    > user to accidentally alter what's displayed on one of them. But text box
    > would work just like in Nick Hodge's suggestion.
    >
    > Here's code:
    >
    > Private Sub txt_Num1_AfterUpdate()
    >
    > If IsNumeric(Me!txt_Num1) And IsNumeric(Me!txt_Num2) Then
    > Me!lbl_Result.Caption = Me!txt_Num1 * Me!txt_Num2
    > End If
    >
    > End Sub
    >
    > Private Sub txt_Num2_AfterUpdate()
    > If IsNumeric(Me!txt_Num1) And IsNumeric(Me!txt_Num2) Then
    > Me!lbl_Result.Caption = Me!txt_Num1 * Me!txt_Num2
    > End If
    > End Sub
    >
    >
    >
    > "gem" wrote:
    >
    > > i need to multiply two numbers from two different text boxes then show the
    > > answer in another text box, this is on an excel userform!
    > > Can anyone help?
    > > thanks


  6. #6
    Dave Peterson
    Guest

    Re: multiply two numbers and show the answer in a textbox

    You can format that result the way you want:

    Me.lbl_Result.Caption = Format(Me.txt_Num1 * Me.txt_Num2, "00.0000")

    I think most Excel developers would use "Me." instead of "Me!".

    Me! is from Access??????




    gem wrote:
    >
    > Thanks JLatham. it worked!!!
    > one more thing though. there is only one digit after the decimal point,how
    > do i change that in the properties?
    >
    > "JLatham" wrote:
    >
    > > You could also try these - basically says that after typing something into
    > > one of the text boxes, verify that both text boxes contain numeric
    > > information and if they do, then multiply them and put the result in a label
    > > as its caption.
    > >
    > > I chose the Label instead of a text box because it's more difficult for the
    > > user to accidentally alter what's displayed on one of them. But text box
    > > would work just like in Nick Hodge's suggestion.
    > >
    > > Here's code:
    > >
    > > Private Sub txt_Num1_AfterUpdate()
    > >
    > > If IsNumeric(Me!txt_Num1) And IsNumeric(Me!txt_Num2) Then
    > > Me!lbl_Result.Caption = Me!txt_Num1 * Me!txt_Num2
    > > End If
    > >
    > > End Sub
    > >
    > > Private Sub txt_Num2_AfterUpdate()
    > > If IsNumeric(Me!txt_Num1) And IsNumeric(Me!txt_Num2) Then
    > > Me!lbl_Result.Caption = Me!txt_Num1 * Me!txt_Num2
    > > End If
    > > End Sub
    > >
    > >
    > >
    > > "gem" wrote:
    > >
    > > > i need to multiply two numbers from two different text boxes then show the
    > > > answer in another text box, this is on an excel userform!
    > > > Can anyone help?
    > > > thanks


    --

    Dave Peterson

+ 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