+ Reply to Thread
Results 1 to 12 of 12

With Custom Modified Average Formula

  1. #1
    Registered User
    Join Date
    06-17-2010
    Location
    Orlando, Florida
    MS-Off Ver
    Excel 2003
    Posts
    8

    Exclamation With Custom Modified Average Formula

    I am attempting to create an averaging formula that will average 2 numbers my spreadsheet. Because of inconsistent data, I am having to take in 3 numbers, find the two most revelent numbers that are there, and average the two of them. If I am missing 2 or more of the numbers, I simply return an empty string.

    Because I am having to replicate this formula on several different spreadsheets, I decided to make a User Defined Formula for it to make my life easier.

    I am wanting to convert the following formula into a User Defined Formula:
    =IF(AND(CELL1<>"",CELL2<>""),AVERAGE(CELL1,CELL2),IF(AND(CELL1<>"",CELL3<>""),AVERAGE(CELL1,CELL3),IF(AND(CELL2<>"",CELL3<>""),AVERAGE(CELL2,CELL3),"")))

    I have absolutely no experience with the Module Programming and very little experience in Excel Formulas, but I have experience with programming languages, so I was able to work myself around the syntax. Here is my attempt on programming the formula:
    Please Login or Register  to view this content.
    This currently returns: #VALUE!


    I assume my mistake is miniscule, but I can use help nonetheless.
    Last edited by royUK; 06-17-2010 at 02:51 PM. Reason: add code tags

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

    re: With Custom Modified Average Formula

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    Added this time

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    Edited this time
    Hope that helps.

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

    Free DataBaseForm example

  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: With Custom Modified Average Formula

    Why replace the formula with a User Defined Function?

  4. #4
    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: With Custom Modified Average Formula

    You could simplify the formula:

    =CHOOSE(COUNT(A2:C2)+1, "", "", AVERAGE(A2:C2), AVERAGE(A2:B2))
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    06-17-2010
    Location
    Orlando, Florida
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: With Custom Modified Average Formula

    Thanks for fixing my topic, I will definately be more careful in the future. I've been trying to figure this out all day and I've gotten annoyed so I overlooked my post.

    Quote Originally Posted by royUK View Post
    Why replace the formula with a User Defined Function?
    The reason I want to replace the formula is because I have to use the formula over several different documents, all without consistent formatting. Which means to edit each formula for each sheet, I have to replace 12 cell references and scroll back through at least 36 cells in a row. Whereas If I replace it with the UDF, I will only have to replace 3 cell references each time. The data includes numbers for each month between 2010 and 1990, so the size of the spreadsheet is huge and the difference between making 12 and 3 cell references makes a huge difference in time. Doing this can greatly increase my productivity and thus increase the amount of non-working I have to do at work

    Quote Originally Posted by shg View Post
    You could simplify the formula:

    =CHOOSE(COUNT(A2:C2)+1, "", "", AVERAGE(A2:C2), AVERAGE(A2:B2))
    I'm having to average just 2 numbers that can be seperated throughout the spreadsheet, not a range of numbers.
    Last edited by aussiemcgr; 06-17-2010 at 03:25 PM. Reason: More Information

  6. #6
    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: With Custom Modified Average Formula

    =choose(count(a2,b2,c2)+1, "", "", average(a2,b2,c2), average(a2,b2))

  7. #7
    Registered User
    Join Date
    06-17-2010
    Location
    Orlando, Florida
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: With Custom Modified Average Formula

    Quote Originally Posted by shg View Post
    =choose(count(a2,b2,c2)+1, "", "", average(a2,b2,c2), average(a2,b2))
    That just returns TRUE every time. My original formula returns the average (double) of the two most recent provided data (cell1 being the most recent and cell3 being the least recent) or an empty string if there isnt 2 or more provided data.

  8. #8
    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: With Custom Modified Average Formula

    You'd have to show me an example of that formula returning TRUE.

  9. #9
    Registered User
    Join Date
    06-17-2010
    Location
    Orlando, Florida
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: With Custom Modified Average Formula

    Quote Originally Posted by shg View Post
    You'd have to show me an example of that formula returning TRUE.
    Not sure how I got TRUE, but I'm not anymore.

    Regardless, the formula isnt completely simplified. This is what it should be:
    Please Login or Register  to view this content.
    I do have a question about it though. When is
    Please Login or Register  to view this content.
    used?

  10. #10
    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: With Custom Modified Average Formula

    =CHOOSE(COUNT(A1,B1,C1)+1, "", "", AVERAGE(A1,B1,C1), AVERAGE(A1,B1)) (mine)

    =CHOOSE(COUNT(B1,C1,D1)+1, "", AVERAGE(B1,D1), AVERAGE(B1,C1,D1), AVERAGE(B1,C1)) (yours)

    Your formula averages B1 and D1 when there's only one number among the three cells, which doesn't follow your prior formula.

    When is AVERAGE(B1,C1,D1) used?
    When any two of the three cells have numbers. The non-numeric value is ignored by AVERAGE.
    Last edited by shg; 06-18-2010 at 11:11 AM.

  11. #11
    Registered User
    Join Date
    06-17-2010
    Location
    Orlando, Florida
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: With Custom Modified Average Formula

    Quote Originally Posted by shg View Post
    =CHOOSE(COUNT(A1,B1,C1)+1, "", "", AVERAGE(A1,B1,C1), AVERAGE(A1,B1)) (mine)

    =CHOOSE(COUNT(B1,C1,D1)+1, "", AVERAGE(B1,D1), AVERAGE(B1,C1,D1), AVERAGE(B1,C1)) (yours)

    Your formula averages B1 and D1 when there's only one number among the three cells, which doesn't follow your prior formula.



    When any two of the three cells have numbers. The non-numeric value is ignored by AVERAGE.
    I received nothing when B1 and D1 had numbers but C1 didnt. When I added the AVERAGE(B1,D1), it did it average the two available.

  12. #12
    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: With Custom Modified Average Formula

    I'm running out of things to say. Do these answers look right to you?

    Please Login or Register  to view this content.
    The formula in D2 and down is

    =CHOOSE(COUNT(A2,B2,C2)+1, "", "", AVERAGE(A2,B2,C2), AVERAGE(A2,B2))
    Last edited by shg; 06-20-2010 at 03:32 PM.

+ 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