+ Reply to Thread
Results 1 to 7 of 7

How do i calculate the average between cells using VBA?

Hybrid View

  1. #1
    Registered User
    Join Date
    01-02-2012
    Location
    Ebbw Vale
    MS-Off Ver
    Excel 2007
    Posts
    20

    Question How do i calculate the average between cells using VBA?

    Hi all.
    wondering if you can help me. I'm running out of time with my tutorial and struggling. complete newbie.. this is what im after...
    i have been asked to work out the average mark out of 100 of 4 assignments with a 20 % weighting and an average mark out of 2 exams with an 80% weighting. i made the spreadsheet with all the results etc in so i need to use vba to write the code to work these out. theres a pile more but if someone could please give me a helping hand just with thsi bit hopefully i will be able to work out the rest.

    I will attach my spreadsheet, very simple but im also very new!

    thanks!
    Excel VBA Tutorial.xlsm

  2. #2
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: How do i calculate the average between cells using VBA?

    Hi,

    I have given the calculation formulas in the attached sheet, please review them and let us know if this is fine and then we can further proceed with VBA. Thanks.

    Regards,
    DILIPandey

    <click on below 'star' if this helps>
    Attached Files Attached Files
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), [email protected]

  3. #3
    Registered User
    Join Date
    01-02-2012
    Location
    Ebbw Vale
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: How do i calculate the average between cells using VBA?

    Thanks for that.
    That looks like the kind of thing i need yes, apart from the grading i guess will need select case from A-F or something of the sort

    this is the code i have come up with so far but i am getting error "object error 424" object required.



    Function assignmentaverage()

    Range("G2").Value = Application.Average(Range("C2:F2")).Value
    Range("G3").Value = Application.Average(Range("C3:F3")).Value
    Range("G4").Value = Application.Average(Range("C4:F4")).Value
    Range("G5").Value = Application.Average(Range("C5:F5")).Value

    End Function


    hope you can help

    *U P D A T E*

    I Have now worked this out as :

    Range("G2").Value = Application.WorksheetFunction.Average(Worksheets("sheet1").Range("C2:F2"))
    Range("G3").Value = Application.WorksheetFunction.Average(Worksheets("sheet1").Range("C3:F3"))
    Range("G4").Value = Application.WorksheetFunction.Average(Worksheets("sheet1").Range("C4:F4"))
    Range("G5").Value = Application.WorksheetFunction.Average(Worksheets("sheet1").Range("C5:F5"))

    however i still need a weighting of 20% on the assignment average and 80 on the exam... cant seem to do this..
    Last edited by 10121730; 01-10-2012 at 04:28 PM. Reason: UPDATE

  4. #4
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: How do i calculate the average between cells using VBA?

    Why VBA, why not just use formulas?

  5. #5
    Registered User
    Join Date
    01-02-2012
    Location
    Ebbw Vale
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: How do i calculate the average between cells using VBA?

    the reason i am using vba is because that is what i've been asked. It's all to do with getting us familiar with vba as we will be moving onto things that can only be handles by vba and not by formulas within excel.

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How do i calculate the average between cells using VBA?

    Hi 10121730
    Please use code tags around your code.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  7. #7
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: How do i calculate the average between cells using VBA?

    Hmmm! One simple statement that uses a worksheet function, can't see that helping to get you familiar with VBA!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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