+ Reply to Thread
Results 1 to 16 of 16

User Form Formulas - Sum

  1. #1
    Registered User
    Join Date
    12-04-2015
    Location
    Wisconsin
    MS-Off Ver
    2013
    Posts
    19

    User Form Formulas - Sum

    I have a user form where the user puts in a number of cases (QuantityTextBox(1-6) ). I then used a fixed weight to calculate the Net and Gross weight. I then want the total weight so I didn't know how to sum it so I added each box. The problem I have is that if the QuantityTextBox is left blank the sum doesn't fill in. There are times where certain items won't be entered. If they type a zero in the quantity field the sum formula works.

    Please Login or Register  to view this content.
    Thanks!
    Nole68
    Last edited by Nole68; 02-03-2016 at 03:28 PM.

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: User Form Formulas - Sum

    Please upload a sample workbook with your userform and code, it will make it a lot easier for people to help you out.
    Also, when posting code, please use code tags. To do this, highlight your code in the post then click the # symbol. You will have to click Edit post at the bottom right hand side of your post first.
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Registered User
    Join Date
    12-04-2015
    Location
    Wisconsin
    MS-Off Ver
    2013
    Posts
    19

    Re: User Form Formulas - Sum

    Thanks gmr4evr1.. I won't be able to post the workbook as it has too much sales information in it. I can write this in excel =sum(A1:A6) but not in VBA. It should be simple, but I am sure it's not sum and the zero needing to be in there is something too.

  4. #4
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: User Form Formulas - Sum

    Going to be difficult to help but, have your tried adding .Value to your code?
    Example
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    12-04-2015
    Location
    Wisconsin
    MS-Off Ver
    2013
    Posts
    19

    Re: User Form Formulas - Sum

    I went ahead and stripped out as much as I can... I don't want to have to type zeros in the qty text boxes and still get the total of them all to add up in the total gross and net weight texst box.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    12-04-2015
    Location
    Wisconsin
    MS-Off Ver
    2013
    Posts
    19

    Re: User Form Formulas - Sum

    thanks gmr4evr1 ... Didn't change anything

  7. #7
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: User Form Formulas - Sum

    Ok, I realize that this may not be the best solution, but, it works. Problem is, it's going to require adding a bit of code to your existing code.
    Put this at the beginning of your CommandButton4_Click() code...After On Error Resume Next and before 'Calculate export value
    Please Login or Register  to view this content.
    Do this for each of your quantity, net weight and gross weight textboxes and it should work.

  8. #8
    Registered User
    Join Date
    12-04-2015
    Location
    Wisconsin
    MS-Off Ver
    2013
    Posts
    19

    Re: User Form Formulas - Sum

    Thanks.. I am heading out to catch a plane on vacation so I will look into this Monday. What about a better formula for summing up the NetWeightCaseTextBox1 - 5 and Gross??? That formula seems kind of green but I can't find something for sum.

  9. #9
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: User Form Formulas - Sum

    When it comes to using a formula in code, I am totally lost, so I'm afraid I wont be able to help you there.
    Have a safe trip and enjoy the vacay.
    Last edited by gmr4evr1; 02-03-2016 at 07:10 PM.

  10. #10
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: User Form Formulas - Sum

    I got kinda bored so I went ahead and wrote the code for you that I was talking about.
    Please Login or Register  to view this content.

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

    Re: User Form Formulas - Sum

    The entrys in a textbox are strings, not numbers, they can't be added.
    You can use the Val function to convert from string to number

    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.

  12. #12
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: User Form Formulas - Sum

    You can also set the default value of the textbox to 0 in the properties panel.
    David
    (*) Reputation points appreciated.

  13. #13
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: User Form Formulas - Sum

    Good point David, I hadn't thought of that. Maybe that would work better for the OP.

  14. #14
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: User Form Formulas - Sum

    Mike's solution works great as well.

  15. #15
    Registered User
    Join Date
    12-04-2015
    Location
    Wisconsin
    MS-Off Ver
    2013
    Posts
    19

    Re: User Form Formulas - Sum

    I liked the default value idea but it didn't seem to work so I went with Mike's solution. PERFECT!! Because the variable was not set it defaulted to strings, so using the Val Function the variable was changed to number and allowed the calculation?

    What about the Sum of the 6 text boxes. Is there a better sum formula?

    Thanks for all your help guys!

    Tom

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

    Re: User Form Formulas - Sum

    You might try this, to see if Excels automatic type conversion will kick in.
    Please Login or Register  to view this content.
    But I dislike trusting automatic conversion (who knows what defaults they might change next version).
    Please Login or Register  to view this content.
    Tells the program exactly what you want it to do. You don't have to trust the default settings.

+ 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. [SOLVED] User Form to execute search and return all values to the user form for editing
    By allwrighty in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-11-2013, 10:40 PM
  2. Replies: 3
    Last Post: 02-06-2012, 09:39 AM
  3. Copying formulas via user form
    By ncaravela in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-03-2010, 11:11 AM
  4. User form with formulas (excel 2007)
    By Novis in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-19-2009, 03:08 PM
  5. Replies: 0
    Last Post: 06-05-2006, 02:45 AM
  6. FillAdjacentCell.Formulas = True in User Form
    By Vicky in forum Excel General
    Replies: 0
    Last Post: 05-29-2006, 01:25 AM

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