+ Reply to Thread
Results 1 to 7 of 7

Want Average on userform textboxes to ignore blank textboxes

  1. #1
    Registered User
    Join Date
    09-18-2018
    Location
    United States
    MS-Off Ver
    office 365 business
    Posts
    4

    Want Average on userform textboxes to ignore blank textboxes

    I am trying to calculate averages within my userform. Each item is taking two values and needs to average them into a new textbox. There are 28 averages that need to be performed when I click my "average Button"

    Please Login or Register  to view this content.
    This code works just fine when both textbox2 and 3 have data in them but there is the possibility that one of them will be blank. What do i have to add to this code to make it ignore blank values like the function does in a normal spread sheet? Or is there a different code that will provide these results?
    Last edited by 6StringJazzer; 10-10-2018 at 10:53 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Average calculations within userform

    I would recommend that you write your own function.
    Please Login or Register  to view this content.
    Then
    Please Login or Register  to view this content.
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member.

    I also tweaked your title to more accurately reflect your question.

    --6StringJazzer
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    09-18-2018
    Location
    United States
    MS-Off Ver
    office 365 business
    Posts
    4

    Re: Average calculations within userform

    Do i have this put in correctly? when i try to run this i get a compile error.

    Please Login or Register  to view this content.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Want Average on userform textboxes to ignore blank textboxes

    No. The Function is a separate procedure. It goes outside your Sub.


    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-18-2018
    Location
    United States
    MS-Off Ver
    office 365 business
    Posts
    4

    Re: Want Average on userform textboxes to ignore blank textboxes

    Got it and it works like a charm. This puts an end to several months of trying.

    Thanks so much!

  6. #6
    Registered User
    Join Date
    09-18-2018
    Location
    United States
    MS-Off Ver
    office 365 business
    Posts
    4

    Re: Want Average on userform textboxes to ignore blank textboxes

    One more question. If both textboxes are blank the function averages them to zero. If they are both blank i would like it to just ignore it and leave it blank.
    when i try and switch the
    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    i get a run time error 13 type mismatch.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Want Average on userform textboxes to ignore blank textboxes

    That's because the Function returns a Double. It can't return a blank. Change it to

    Please Login or Register  to view this content.

+ 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] Select all text in textboxes when i click textboxes in simple way
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-26-2017, 03:27 AM
  2. Replies: 5
    Last Post: 12-07-2016, 07:41 AM
  3. Sum or average of multiple textboxes in a cell
    By 10M in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2015, 07:48 AM
  4. Replies: 0
    Last Post: 02-04-2015, 03:46 PM
  5. [SOLVED] UserForm VBA to ignore blank textboxes
    By PDBartlett in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-04-2014, 10:44 AM
  6. Replies: 1
    Last Post: 11-29-2010, 06:56 AM
  7. [SOLVED] AVERAGE VALUES IN TEXTBOXES!!!!!
    By michael sofianos in forum Excel General
    Replies: 1
    Last Post: 02-21-2005, 07:06 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