Consulting

Results 1 to 6 of 6

Thread: Multiply Values in a Textbox

  1. #1
    VBAX Regular
    Joined
    Feb 2007
    Location
    Illinois
    Posts
    68
    Location

    Multiply Values in a Textbox

    i have a quantity box and a price box and naturally a total. how do i multiply the first two boxes to put the price in the third.

    this is what i have so far and its not working

    [vba]TextBox1e = TextBox1a.Value * TextBoxq1.Value[/vba]

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    This works for me
    Private Sub UserForm_Initialize()
    TextBox1.Value = 3
    TextBox2.Value = 2
    TextBox3.Value = TextBox1.Value * TextBox2.Value
    End Sub
    Last edited by Aussiebear; 04-12-2023 at 06:25 PM. Reason: Adjusted the code tags
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    Feb 2007
    Location
    Illinois
    Posts
    68
    Location
    thats only works once. i want to change one of the numbers and have the total update.

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    use textbox change or update
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    VBAX Regular
    Joined
    Feb 2007
    Location
    Illinois
    Posts
    68
    Location
    I had the Change but its not working.

    [vba]Sub txtq1_Change()
    txt1e = txt1q.Value * txt1d.Value
    End Sub[/vba]

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Private Sub TextBox1_AfterUpdate()
    DoUpdate
    End Sub
    
    Private Sub TextBox2_AfterUpdate()
    DoUpdate
    End Sub
    
    Sub DoUpdate()
    If TextBox1.Value = "" Then TextBox1.Value = 0
    If TextBox2.Value = "" Then TextBox2.Value = 0
    TextBox3.Value = TextBox1.Value * TextBox2.Value
    End Sub
    Last edited by Aussiebear; 04-12-2023 at 06:27 PM. Reason: Adjusted the code tags
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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