+ Reply to Thread
Results 1 to 7 of 7

VBA Code to Calculate Average of Every Row

  1. #1
    Registered User
    Join Date
    03-16-2017
    Location
    Hamburg, Germany
    MS-Off Ver
    2016
    Posts
    44

    VBA Code to Calculate Average of Every Row

    Hello Excel Experts,

    I have a spreadsheet (attached) where rows are days of the week; columns are houses and values are Volts.
    The number of rows and columns can Change from time to time, so I want to know if there is a VBA that could do the following:

    -On the first cell of the first empty cell found write "AVERAGE" and on the first empty cell of the next column "AVERAGE X ,25". (For the example sheet I attached, it would be on M1 and N1).
    -Calculate the average of each complete row, starting at B2, post this average on M2 and then multiply this average by .25 and post on N2.
    -Repeat on each row until there is no more data.

    I have been trying to get this for a couple hours now, however from what I learned in the couple days barely allows me to look for the first empty column on the sheet.

    Thank you very much in advance!

    Jorge
    Attached Files Attached Files
    Last edited by jorgeflores; 11-02-2017 at 04:21 AM. Reason: Problem Solved

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,761

    Re: VBA Code to Calculate Average of Every Row

    try this

    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: VBA Code to Calculate Average of Every Row

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    03-16-2017
    Location
    Hamburg, Germany
    MS-Off Ver
    2016
    Posts
    44

    Re: VBA Code to Calculate Average of Every Row

    Hello alansidman,

    This is exactly what I needed, this is awesome, thank you!

    Jorge

  5. #5
    Registered User
    Join Date
    03-16-2017
    Location
    Hamburg, Germany
    MS-Off Ver
    2016
    Posts
    44

    Re: VBA Code to Calculate Average of Every Row

    Hello AlphaFrog,

    This also works perfectly! What is the difference between this and the Code from alansidman?
    I am curious about it,

    Jorge

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,761

    Re: VBA Code to Calculate Average of Every Row

    If you have more than 12 columns then the following will work for you also.

    Please Login or Register  to view this content.

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: VBA Code to Calculate Average of Every Row

    Quote Originally Posted by jorgeflores View Post
    Hello AlphaFrog,

    This also works perfectly! What is the difference between this and the Code from alansidman?
    I am curious about it,

    Jorge
    You're welcome. The two codes are similar. There are often different methods in VBA to do the same thing.

+ 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] VBA code to calculate Grade Point Average (GPA)
    By Dineth in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 09-10-2016, 01:46 PM
  2. VBA Code to calculate the total and average values
    By tax112 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-23-2015, 08:25 PM
  3. Formula or VBA Code to calculate the total and average time
    By vutienhp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-09-2015, 11:30 AM
  4. [SOLVED] Use the AVERAGE() function to calculate a sample average
    By alice2011 in forum Excel General
    Replies: 1
    Last Post: 09-24-2014, 08:04 AM
  5. Code to calculate the last 720 valid hours THEN give a rollin average of the data
    By joeyheaf in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-03-2012, 02:39 PM
  6. [SOLVED] VBA code to calculate Average value of number combinations
    By Chubster in forum Excel General
    Replies: 2
    Last Post: 03-28-2012, 08:50 PM
  7. Calculate average withouot incorporating sub average
    By ybu1106 in forum Excel General
    Replies: 25
    Last Post: 06-15-2010, 09:47 AM

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