+ Reply to Thread
Results 1 to 12 of 12

Multipling the value of 3 text boxes

  1. #1
    Forum Contributor
    Join Date
    12-30-2005
    Location
    Mobile, AL
    Posts
    102

    Lightbulb Multipling the value of 3 text boxes

    Ok, this one should be easy, but it has me stumped. I am not finding any good lead on the net either.

    Here is the problem. I want to multiply the value of three text boxes and put the resulting value into a forth text box. This value will be calculated on a change event. I know this can be done in code, but I haven't the foggiest where to begin.

    Any suggestions?

    Thanks in advance,
    Amber

  2. #2
    Tim Williams
    Guest

    Re: Multipling the value of 3 text boxes

    Text boxes where?

    Tim

    --
    Tim Williams
    Palo Alto, CA


    "Amber_D_Laws" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > Ok, this one should be easy, but it has me stumped. I am not finding any
    > good lead on the net either.
    >
    > Here is the problem. I want to multiply the value of three text boxes
    > and put the resulting value into a forth text box. This value will be
    > calculated on a change event. I know this can be done in code, but I
    > haven't the foggiest where to begin.
    >
    > Any suggestions?
    >
    > Thanks in advance,
    > Amber
    >
    >
    > --
    > Amber_D_Laws
    > ------------------------------------------------------------------------
    > Amber_D_Laws's Profile:

    http://www.excelforum.com/member.php...o&userid=30012
    > View this thread: http://www.excelforum.com/showthread...hreadid=513735
    >




  3. #3
    Forum Contributor
    Join Date
    12-30-2005
    Location
    Mobile, AL
    Posts
    102
    On a multi-page user form.

    Amber

    Quote Originally Posted by Tim Williams
    Text boxes where?

    Tim

    --
    Tim Williams
    Palo Alto, CA


    "Amber_D_Laws" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > Ok, this one should be easy, but it has me stumped. I am not finding any
    > good lead on the net either.
    >
    > Here is the problem. I want to multiply the value of three text boxes
    > and put the resulting value into a forth text box. This value will be
    > calculated on a change event. I know this can be done in code, but I
    > haven't the foggiest where to begin.
    >
    > Any suggestions?
    >
    > Thanks in advance,
    > Amber
    >
    >
    > --
    > Amber_D_Laws
    > ------------------------------------------------------------------------
    > Amber_D_Laws's Profile:

    http://www.excelforum.com/member.php...o&userid=30012
    > View this thread: http://www.excelforum.com/showthread...hreadid=513735
    >

  4. #4
    Forum Contributor
    Join Date
    12-30-2005
    Location
    Mobile, AL
    Posts
    102
    Any one else think they can help?

    Amber

  5. #5
    Dave Peterson
    Guest

    Re: Multipling the value of 3 text boxes

    Maybe something like:

    Option Explicit
    Private Sub TextBox1_Change()
    Call TBChange
    End Sub
    Private Sub TextBox2_Change()
    Call TBChange
    End Sub
    Private Sub TextBox3_Change()
    Call TBChange
    End Sub
    Private Sub TBChange()
    Dim myValue As Double
    myValue = 0
    If IsNumeric(Me.TextBox1.Value) Then
    myValue = myValue + CDbl(Me.TextBox1.Value)
    End If
    If IsNumeric(Me.TextBox2.Value) Then
    myValue = myValue + CDbl(Me.TextBox2.Value)
    End If
    If IsNumeric(Me.TextBox3.Value) Then
    myValue = myValue + CDbl(Me.TextBox3.Value)
    End If

    'formatted?
    Me.TextBox4.Value = Format(myValue, "00.00")
    End Sub


    Amber_D_Laws wrote:
    >
    > Any one else think they can help?
    >
    > Amber
    >
    > --
    > Amber_D_Laws
    > ------------------------------------------------------------------------
    > Amber_D_Laws's Profile: http://www.excelforum.com/member.php...o&userid=30012
    > View this thread: http://www.excelforum.com/showthread...hreadid=513735


    --

    Dave Peterson

  6. #6
    Forum Contributor
    Join Date
    12-30-2005
    Location
    Mobile, AL
    Posts
    102
    That's great Dave, but a little more complicated than I expected.
    If I were doing this in the worksheet it would be...

    A3*A4*A5

    but, this is the userform, and they are textboxes, so I was expecting something more along the lines of

    (txtUnitPrice.Value*txtTATMultiplier*txtSampleNum).Value = txtTotalPrice

    of course, I could be completly off base. I have to admit, I don't even follow the logic of your code. I can't tell where the multiplication is happening. Let me know. The txt's above are the names of the textboxes. Sorry if my earlier posts were unclear. I forget sometimes that you all are not in my head and might not know what I am talking about.

    Ha!
    Thanks again Dave,
    Amber



    Quote Originally Posted by Dave Peterson
    Maybe something like:

    Option Explicit
    Private Sub TextBox1_Change()
    Call TBChange
    End Sub
    Private Sub TextBox2_Change()
    Call TBChange
    End Sub
    Private Sub TextBox3_Change()
    Call TBChange
    End Sub
    Private Sub TBChange()
    Dim myValue As Double
    myValue = 0
    If IsNumeric(Me.TextBox1.Value) Then
    myValue = myValue + CDbl(Me.TextBox1.Value)
    End If
    If IsNumeric(Me.TextBox2.Value) Then
    myValue = myValue + CDbl(Me.TextBox2.Value)
    End If
    If IsNumeric(Me.TextBox3.Value) Then
    myValue = myValue + CDbl(Me.TextBox3.Value)
    End If

    'formatted?
    Me.TextBox4.Value = Format(myValue, "00.00")
    End Sub


    Amber_D_Laws wrote:
    >
    > Any one else think they can help?
    >
    > Amber
    >
    > --
    > Amber_D_Laws
    > ------------------------------------------------------------------------
    > Amber_D_Laws's Profile: http://www.excelforum.com/member.php...o&userid=30012
    > View this thread: http://www.excelforum.com/showthread...hreadid=513735


    --

    Dave Peterson

  7. #7
    Forum Contributor
    Join Date
    06-13-2004
    Posts
    120
    You could also call a change event that is a little simplier.

    Sub Multiply_Value()
    On Error Resume Next
    textbox4.value = textbox1.value * textbox2.value * textbox3.value
    end sub

    and then on the change event for each of the 3 textboxs, call the Multiply_Value command.

    The only difference in this one, is if any of the 3 boxes do not contain a value, then box4 will not generate a value.

  8. #8
    Forum Contributor
    Join Date
    12-30-2005
    Location
    Mobile, AL
    Posts
    102
    Well....that is a lot more simple, and practically what I thought it would be!
    The change event I want to attach this to is:
    Sub cmbMethodName_Change()
    will that matter, or can I just insert said code?

    Thanks dok112!


    Quote Originally Posted by dok112
    You could also call a change event that is a little simplier.

    Sub Multiply_Value()
    On Error Resume Next
    textbox4.value = textbox1.value * textbox2.value * textbox3.value
    end sub

    and then on the change event for each of the 3 textboxs, call the Multiply_Value command.

    The only difference in this one, is if any of the 3 boxes do not contain a value, then box4 will not generate a value.

  9. #9
    Forum Contributor
    Join Date
    06-13-2004
    Posts
    120
    Yeah, you can insert the code. Now, if you changed the name of the textboxes from the standard, you will need to update the names in the code. Also, if you have the boxes spanning over multiple sheets in the form, then you will need to tell the system which box you are using. for example. if you have 2 userforms both named userform1 and userform 2 and both have textboxes, then you need to identify them as userform1.textbox1.value, userform2.textbox3.value etc etc...

  10. #10
    Forum Contributor
    Join Date
    12-30-2005
    Location
    Mobile, AL
    Posts
    102
    Thanks, and Thanks again!!!
    I will implement the code ASAP, when I return to the office that is.
    Have a great weekend everybody!




    Quote Originally Posted by dok112
    Yeah, you can insert the code. Now, if you changed the name of the textboxes from the standard, you will need to update the names in the code. Also, if you have the boxes spanning over multiple sheets in the form, then you will need to tell the system which box you are using. for example. if you have 2 userforms both named userform1 and userform 2 and both have textboxes, then you need to identify them as userform1.textbox1.value, userform2.textbox3.value etc etc...
    Amber D. Laws
    "My mother used to say an ounce of pretention is worth a pound of manure."
    --Olympia Dukakis, as Clairee Belcher in Steel Magnolias (1989)

  11. #11
    Dave Peterson
    Guest

    Re: Multipling the value of 3 text boxes

    First, I used sum, not product.

    But you could modify the original suggestion to:

    Option Explicit
    Private Sub TextBox1_Change()
    Call TBChange
    End Sub
    Private Sub TextBox2_Change()
    Call TBChange
    End Sub
    Private Sub TextBox3_Change()
    Call TBChange
    End Sub
    Private Sub TBChange()
    Dim myValue As Double
    myValue = 1
    If IsNumeric(Me.TextBox1.Value) Then
    myValue = myValue * CDbl(Me.TextBox1.Value)
    End If
    If IsNumeric(Me.TextBox2.Value) Then
    myValue = myValue * CDbl(Me.TextBox2.Value)
    End If
    If IsNumeric(Me.TextBox3.Value) Then
    myValue = myValue * CDbl(Me.TextBox3.Value)
    End If

    'formatted?
    Me.TextBox4.Value = Format(myValue, "00.00")
    End Sub

    The majority of the code is to prevent an error -- when you try to multiply
    something that's not a number.

    You could choose to ignore the error (on error resume next) or try to avoid it
    in code. The choice is your own (obviously).

    Amber_D_Laws wrote:
    >
    > That's great Dave, but a little more complicated than I expected.
    > If I were doing this in the worksheet it would be...
    >
    > A3*A4*A5
    >
    > but, this is the userform, and they are textboxes, so I was expecting
    > something more along the lines of
    >
    > (txtUnitPrice.Value*txtTATMultiplier*txtSampleNum).Value =
    > txtTotalPrice
    >
    > of course, I could be completly off base. I have to admit, I don't even
    > follow the logic of your code. I can't tell where the multiplication is
    > happening. Let me know. The txt's above are the names of the textboxes.
    > Sorry if my earlier posts were unclear. I forget sometimes that you all
    > are not in my head and might not know what I am talking about.
    >
    > Ha!
    > Thanks again Dave,
    > Amber
    >
    > Dave Peterson Wrote:
    > > Maybe something like:
    > >
    > > Option Explicit
    > > Private Sub TextBox1_Change()
    > > Call TBChange
    > > End Sub
    > > Private Sub TextBox2_Change()
    > > Call TBChange
    > > End Sub
    > > Private Sub TextBox3_Change()
    > > Call TBChange
    > > End Sub
    > > Private Sub TBChange()
    > > Dim myValue As Double
    > > myValue = 0
    > > If IsNumeric(Me.TextBox1.Value) Then
    > > myValue = myValue + CDbl(Me.TextBox1.Value)
    > > End If
    > > If IsNumeric(Me.TextBox2.Value) Then
    > > myValue = myValue + CDbl(Me.TextBox2.Value)
    > > End If
    > > If IsNumeric(Me.TextBox3.Value) Then
    > > myValue = myValue + CDbl(Me.TextBox3.Value)
    > > End If
    > >
    > > 'formatted?
    > > Me.TextBox4.Value = Format(myValue, "00.00")
    > > End Sub
    > >
    > >
    > > Amber_D_Laws wrote:
    > > >
    > > > Any one else think they can help?
    > > >
    > > > Amber
    > > >
    > > > --
    > > > Amber_D_Laws
    > > >

    > > ------------------------------------------------------------------------
    > > > Amber_D_Laws's Profile:

    > > http://www.excelforum.com/member.php...o&userid=30012
    > > > View this thread:

    > > http://www.excelforum.com/showthread...hreadid=513735
    > >
    > > --
    > >
    > > Dave Peterson

    >
    > --
    > Amber_D_Laws
    > ------------------------------------------------------------------------
    > Amber_D_Laws's Profile: http://www.excelforum.com/member.php...o&userid=30012
    > View this thread: http://www.excelforum.com/showthread...hreadid=513735


    --

    Dave Peterson

  12. #12
    Forum Contributor
    Join Date
    12-30-2005
    Location
    Mobile, AL
    Posts
    102
    Thanks Dave, that makes much more sense now!
    I appreciated the time you put into this. The three text boxes in question are automaticly populated through other code, and therefore will not ever be anything but numeric. However, your suggestion does give food for thought. Afterall it is better to cover one's behind than to try and figure out how to put out the flames once it is on fire.

    I think between you and dok112 I have this thing sorted out.

    Until later,
    Amber

    Quote Originally Posted by Dave Peterson
    First, I used sum, not product.

    But you could modify the original suggestion to:

    Option Explicit
    Private Sub TextBox1_Change()
    Call TBChange
    End Sub
    Private Sub TextBox2_Change()
    Call TBChange
    End Sub
    Private Sub TextBox3_Change()
    Call TBChange
    End Sub
    Private Sub TBChange()
    Dim myValue As Double
    myValue = 1
    If IsNumeric(Me.TextBox1.Value) Then
    myValue = myValue * CDbl(Me.TextBox1.Value)
    End If
    If IsNumeric(Me.TextBox2.Value) Then
    myValue = myValue * CDbl(Me.TextBox2.Value)
    End If
    If IsNumeric(Me.TextBox3.Value) Then
    myValue = myValue * CDbl(Me.TextBox3.Value)
    End If

    'formatted?
    Me.TextBox4.Value = Format(myValue, "00.00")
    End Sub

    The majority of the code is to prevent an error -- when you try to multiply
    something that's not a number.

    You could choose to ignore the error (on error resume next) or try to avoid it
    in code. The choice is your own (obviously).

    Amber_D_Laws wrote:
    >
    > That's great Dave, but a little more complicated than I expected.
    > If I were doing this in the worksheet it would be...
    >
    > A3*A4*A5
    >
    > but, this is the userform, and they are textboxes, so I was expecting
    > something more along the lines of
    >
    > (txtUnitPrice.Value*txtTATMultiplier*txtSampleNum).Value =
    > txtTotalPrice
    >
    > of course, I could be completly off base. I have to admit, I don't even
    > follow the logic of your code. I can't tell where the multiplication is
    > happening. Let me know. The txt's above are the names of the textboxes.
    > Sorry if my earlier posts were unclear. I forget sometimes that you all
    > are not in my head and might not know what I am talking about.
    >
    > Ha!
    > Thanks again Dave,
    > Amber
    >
    > Dave Peterson Wrote:
    > > Maybe something like:
    > >
    > > Option Explicit
    > > Private Sub TextBox1_Change()
    > > Call TBChange
    > > End Sub
    > > Private Sub TextBox2_Change()
    > > Call TBChange
    > > End Sub
    > > Private Sub TextBox3_Change()
    > > Call TBChange
    > > End Sub
    > > Private Sub TBChange()
    > > Dim myValue As Double
    > > myValue = 0
    > > If IsNumeric(Me.TextBox1.Value) Then
    > > myValue = myValue + CDbl(Me.TextBox1.Value)
    > > End If
    > > If IsNumeric(Me.TextBox2.Value) Then
    > > myValue = myValue + CDbl(Me.TextBox2.Value)
    > > End If
    > > If IsNumeric(Me.TextBox3.Value) Then
    > > myValue = myValue + CDbl(Me.TextBox3.Value)
    > > End If
    > >
    > > 'formatted?
    > > Me.TextBox4.Value = Format(myValue, "00.00")
    > > End Sub
    > >
    > >
    > > Amber_D_Laws wrote:
    > > >
    > > > Any one else think they can help?
    > > >
    > > > Amber
    > > >
    > > > --
    > > > Amber_D_Laws
    > > >

    > > ------------------------------------------------------------------------
    > > > Amber_D_Laws's Profile:

    > > http://www.excelforum.com/member.php...o&userid=30012
    > > > View this thread:

    > > http://www.excelforum.com/showthread...hreadid=513735
    > >
    > > --
    > >
    > > Dave Peterson

    >
    > --
    > Amber_D_Laws
    > ------------------------------------------------------------------------
    > Amber_D_Laws's Profile: http://www.excelforum.com/member.php...o&userid=30012
    > View this thread: http://www.excelforum.com/showthread...hreadid=513735


    --

    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