+ Reply to Thread
Results 1 to 15 of 15

Apply formula to text box pending value of another text box

  1. #1
    Registered User
    Join Date
    09-24-2014
    Location
    Pinjarra, Australia
    MS-Off Ver
    2011
    Posts
    45

    Apply formula to text box pending value of another text box

    I'm getting there. Three days and still working on this form

    I have the following text boxes and combo boxes.

    cboxServiceType (combobox)
    txtQty
    txtExcess.

    If the value in cboxService = a specific value - ie "Excess"
    I would like the following formula to be entered into the txtExcess box:-

    =sum txtQty - 4000.

    Is this at all possible? If so how do I write it and where? I assume in the cboxServiceType_Change() Private sub??

    By the way I am using Excel 2011 for Mac in case that has any impact.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Apply formula to text box pending value of another text box

    I can't comment on the Mac ramifications. But the code in the cboxServiceType_Change() macro would be something like this... several examples are shown so you can see how you can handle various values:

    Please Login or Register  to view this content.
    If the Me.Value reference doesn't work, then replace that with cboxServiceType.Value
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    09-24-2014
    Location
    Pinjarra, Australia
    MS-Off Ver
    2011
    Posts
    45

    Re: Apply formula to text box pending value of another text box

    Thanks for the above response, however I get a Run-time error '13' -Type mismatch at:

    txtExcessTank.Value = txtQty.Value - 4000.


    Please Login or Register  to view this content.
    Have I written it write??
    Last edited by mariannehislop; 09-28-2014 at 12:42 PM.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Apply formula to text box pending value of another text box

    It looks ok. At the moment the error occurs, what is the current value of the text box?

    Can there ever be more than one value for this box? The SELECT CASE method is really only needed if there can be more than one possible value and result you want.

  5. #5
    Registered User
    Join Date
    09-24-2014
    Location
    Pinjarra, Australia
    MS-Off Ver
    2011
    Posts
    45

    Re: Apply formula to text box pending value of another text box

    cboxServiceType can be more that one value. When "Septic System >4000" is selected from the list the txtExcessTank is Enabled and I want the formula to be entered. This formula is only relevant when item "Septic System >4000" is selected, otherwise it is empty.

    I have managed to unlock it with:

    Please Login or Register  to view this content.
    Which this part is working fine.

    So when the error occures the txtExcessTank box is blank.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Apply formula to text box pending value of another text box

    I meant the value of the txtQty

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Apply formula to text box pending value of another text box

    Maybe:

    Please Login or Register  to view this content.
    Or

    Please Login or Register  to view this content.
    )
    Last edited by JBeaucaire; 09-28-2014 at 05:55 PM. Reason: Added missing CODE tags.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  8. #8
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Apply formula to text box pending value of another text box

    Strictly speaking, when doing arithmetic with values from TextBoxes, one should convert the string into a number.
    In this regard, Mac's are strict.

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Apply formula to text box pending value of another text box

    Mike, rattling around in my brain is a recollection that CDbl respects intenational settings, and Val doesn't.
    Last edited by shg; 09-28-2014 at 04:23 PM.
    Entia non sunt multiplicanda sine necessitate

  10. #10
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Apply formula to text box pending value of another text box

    Yes, but CDbl("x") throws an type mismatch error. Val("x") = 0.

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Apply formula to text box pending value of another text box

    Nevermind!
    Last edited by xladept; 09-28-2014 at 05:48 PM.

  12. #12
    Registered User
    Join Date
    09-24-2014
    Location
    Pinjarra, Australia
    MS-Off Ver
    2011
    Posts
    45

    Re: Apply formula to text box pending value of another text box

    Thanks Mike. I'm very new to VB coding so not quite following.

    I have initialised the cboxServiceType list with:
    Please Login or Register  to view this content.
    This is working.

    I have this code populating my second combobox txtRate

    Please Login or Register  to view this content.
    Now I would like a formula to go into the txtExcessTank box that says

    If cboxServiceType>4000, then
    txtExcessTank = formula (txtQty) - 4000

    So if the txtQty was 5000, the txtExcessTank should display 1000

    I have added the following code as instructed by you.

    Please Login or Register  to view this content.
    However, when I run the form I get the following error

    "Run-time error '424':
    Object required

    ??
    Last edited by mariannehislop; 09-29-2014 at 08:45 PM.

  13. #13
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Apply formula to text box pending value of another text box

    It looks like were I have txtExcess, the actual name of your text box (txtExcessTank) should be used.

  14. #14
    Registered User
    Join Date
    09-24-2014
    Location
    Pinjarra, Australia
    MS-Off Ver
    2011
    Posts
    45

    Re: Apply formula to text box pending value of another text box

    Thanks Mike. I am using the name txtExcessTank and it still has the same error.

    I have given up on this task and decided to include a formula into a table on the sheet that is working fine. Though would be useful to know for the future.

    Thanks for your effort anyway. Much appreciated

  15. #15
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Apply formula to text box pending value of another text box

    Please Login or Register  to view this content.
    Can't work

    Please Login or Register  to view this content.
    Might work

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. If Cell Text Matches Any Text From Range, Then Apply VLOOKUP?
    By eliot1171 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-12-2013, 09:41 PM
  2. apply existing List, if formula is true, otherwise write text data in cell
    By Lynn Porter in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-07-2013, 08:03 PM
  3. formula apply if cell containt text
    By santoshsapre in forum Excel General
    Replies: 2
    Last Post: 06-21-2012, 11:03 PM
  4. Replies: 3
    Last Post: 05-25-2012, 05:45 PM
  5. [SOLVED] Apply Wrap Text
    By Dee in forum Excel General
    Replies: 1
    Last Post: 01-25-2006, 04:35 PM

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