+ Reply to Thread
Results 1 to 4 of 4

Averaging Text box values excluding blanks in VBA

  1. #1
    Registered User
    Join Date
    10-08-2010
    Location
    Colorado
    MS-Off Ver
    Excel 2003
    Posts
    6

    Averaging Text box values excluding blanks in VBA

    Hello,

    This is my second post on this forum, and I apologize if I do anything incorrectly (I have read the rules and am making every attempt to follow them).

    I have created a sample file (TEST1 attached) to illustrate my questions. In the userform, I have textbox5 averaging when data is entered into textboxes 1-4. It seems like an easy fix, but I cannot figure it out today.

    1.) How do I change the calculation to average only the cells with values in them?
    2.) Does the code have to be input into each textbox_change command in order to work or is there a more efficient way?

    That seems like a good place to start. Thank you in advance for your time and assistance.

    Nolan
    Attached Files Attached Files
    Last edited by nhannigan; 12-28-2010 at 03:28 PM.

  2. #2
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Averaging Text box values excluding blanks in VBA

    1) see the code below. It checks that a textbox contains a number before it adds it to the runnign sum.
    2) there are several ways to do this, but all generate about the same amount of code. VBA will not allow you to share event handlers between controls.
    Please Login or Register  to view this content.
    Last edited by davesexcel; 12-28-2010 at 03:12 PM. Reason: Quoting previous post is not necessary
    Bob
    Click my star if my answer helped you. Mark the thread as [SOLVED] if it has been.

  3. #3
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Averaging Text box values excluding blanks in VBA

    Try this...

    Please Login or Register  to view this content.
    Martin

  4. #4
    Registered User
    Join Date
    10-08-2010
    Location
    Colorado
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Averaging Text box values excluding blanks in VBA

    SOLVED. Both work perfectly. Blane245, it is good to know that the method I have been using is pretty much as good as it gets.

    Thank you both for your quick responses.

+ 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