+ Reply to Thread
Results 1 to 4 of 4

VBA Textbox Calculations

Hybrid View

  1. #1
    Registered User
    Join Date
    03-25-2012
    Location
    England
    MS-Off Ver
    Excel 2007 & Excel 2011 for Mac
    Posts
    79

    VBA Textbox Calculations

    Hi,

    Is there anyway i can adapt the following code to work in the last textbox(6).

    Basically its an adaptation of an excel formula which i wanted to enter into a Userform

    What i have is as follows, i'm just not sure how to syntax it correctly and where to add it in the TextBox6 code

    Many Thanks

    TextBox6 = Sum(TextBox3 - TextBox4) + Sum((TextBox5 / ((TextBox1 / 1) + 1) * (100 - (TextBox2 * 100)) / 100))

  2. #2
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: VBA Textbox Calculations

    Zhb,

    Set up a variable for each textbox item, then simply add them to the formula. For example:

    Dim tb1 as Double
    Dim tb2 as Double
    Dim tb3 as Double
    
    tb1 = cdbl(me.textbox1.value)
    tb2 = cdbl(me.textbox2.value)
    tb3 = cdbl(me.textbox3.value)
    
    textbox6.value = (tb1 + tb2) * tb3 - (tb3 *100)
    Obviously, my example is a made up formula and I didn't create variables for ALL of your textboxes, but I think you can figure it out from there.

    As far as WHERE to add it, this really is up to you and based on need. For example, it may not even be in the TextBox6 code. Instead, it might be in the TextBox5_Exit (meaning as soon as you exit TextBox5, the code runs. It's hard to answer this part of your question without seeing your userform, and explaining what you need it to do.

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: VBA Textbox Calculations

    Alternatively

    
    TextBox6 = CDbl(Sum(TextBox3) - CDbl(TextBox4)) + Sum((CDbl(TextBox5) / _
        ((CDbl(TextBox1) / 1) + 1) * (100 - (CDbl(TextBox2) * 100)) / 100))
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    03-25-2012
    Location
    England
    MS-Off Ver
    Excel 2007 & Excel 2011 for Mac
    Posts
    79

    Re: VBA Textbox Calculations

    Brilliant, thanks both of you

+ 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