+ Reply to Thread
Results 1 to 5 of 5

Excel - VBA Comparing cell values to each column's average

  1. #1
    Registered User
    Join Date
    10-05-2014
    Location
    United States
    MS-Off Ver
    2013
    Posts
    3

    Excel - VBA Comparing cell values to each column's average

    I'm trying to prepare a code in vba for excel. For each month there is a list of values, each month is listed in a separate column, multiple values are listed below each month.

    What I wanted to do is change the color of each cell which value is 4 times smaller than the month's average. So far my code looks like this, each average is calculated like I wanted it, but i can't seem to figure out how to get it to compare the cells only to one column's average, not to all of them consecutively - like it does now.
    Please Login or Register  to view this content.
    Last edited by alansidman; 10-05-2014 at 12:31 PM. Reason: code tags added

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,912

    re: Excel - VBA Comparing cell values to each column's average

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (Because you are new to the forum, I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    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
    Registered User
    Join Date
    10-05-2014
    Location
    United States
    MS-Off Ver
    2013
    Posts
    3

    re: Excel - VBA Comparing cell values to each column's average

    Thank you! I appreciate that I'll be sure to go over the forum rules.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Excel - VBA Comparing cell values to each column's average

    Hello Joseph1220,

    Because your variable Average is nested inside the j loop, it needs to be reset to zero. Otherwise, you accumalte the average for all columns. See the fix below in blue.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Registered User
    Join Date
    10-05-2014
    Location
    United States
    MS-Off Ver
    2013
    Posts
    3

    Re: Excel - VBA Comparing cell values to each column's average

    thank you Leith, however, I reset the average before that and it doesn't accumulate when being calculated. What I wanted to fix there was the fact that it compares the cell values to averages of every column, not only the one which it is placed in.

+ 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. Replies: 19
    Last Post: 03-15-2014, 04:50 PM
  2. Excel 2010 Comparing column values
    By Bill001 in forum Excel General
    Replies: 7
    Last Post: 08-14-2013, 01:32 AM
  3. [SOLVED] Conditional Formatting: Comparing cell with a column of values and applying 3 rules
    By ab231 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-02-2013, 10:30 AM
  4. Replies: 3
    Last Post: 10-15-2012, 10:42 AM
  5. Grouping rows based on column values and comparing row values
    By bernborough in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-27-2010, 10:18 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