+ Reply to Thread
Results 1 to 7 of 7

AverageIF and IFError VBA macro cell formula

  1. #1
    Registered User
    Join Date
    09-13-2024
    Location
    San Diego
    MS-Off Ver
    11
    Posts
    9

    AverageIF and IFError VBA macro cell formula

    I have written an intense macro, that averages a row at a time from a beginning cell to an end cell.

    The following line works fine:
    Please Login or Register  to view this content.
    However, I am now trying to change this to average only cells with non-zeros.

    As many have experienced, when you have a total row with all zeros, it will bug out to only use AverageIF statement, so I was combining IfError statement to combat that.
    I don't think there is an error in the statement, so there must be a rule that this doesn't fit or work within the confines of the rules in VBA.

    But if typed directly in the cell it works. Recorded a R1C1 macro of this to see if I can convert it to VBA variables:
    Recorded:
    Please Login or Register  to view this content.
    Trying to input (but VBA tells me error):
    Please Login or Register  to view this content.
    ANY IDEAS??? thanks in advance!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,011

    Re: AverageIF and IFError VBA macro cell formula

    Try:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,235

    Re: AverageIF and IFError VBA macro cell formula

    Administrative Note:

    Welcome to the forum.

    Is your forum profile showing ONLY the oldest Excel PRODUCT that you need this to work for?

    Members will tailor the solutions they offer to the Office PRODUCT (Excel, NOT Windows) that you have. Please check that your forum profile is up-to-date in this respect. If you aren't sure, in Excel go to File | Account and report what it says below the MS logo at the top of that page. If your product is for Mac, please also state this.

    The three most recent Excel products are Excel 2019, Excel 2021 and MS365 - if you are using MS365, please give this name along with the version number in your profile (e.g. MS365 Version 2306). This is in the About Excel section further down the Account page.

    Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  4. #4
    Registered User
    Join Date
    09-13-2024
    Location
    San Diego
    MS-Off Ver
    11
    Posts
    9

    Re: AverageIF and IFError VBA macro cell formula

    Quote Originally Posted by TMS View Post
    Try:

    Please Login or Register  to view this content.
    Unfortunately, this does NOT work as it doesn't have the AVERAGEIF statement in it, so it averages all cells together whether it's a zero or not, so having say 5 zeros plus a number will divide by a total of 6.
    I did try a varient of this, but it always bugs out using the AVERAGEIF where the commas show up...

    Please Login or Register  to view this content.
    Is AverageIf not allowed in VBA for an Active Cell statement?

  5. #5
    Registered User
    Join Date
    09-13-2024
    Location
    San Diego
    MS-Off Ver
    11
    Posts
    9

    Re: AverageIF and IFError VBA macro cell formula

    Here is a visual picture of the issue, and it does work in the worksheet, formula is correct for J11, however, I can't seem to get the syntax correct in the VBA:
    Attachment 878959

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,011

    Re: AverageIF and IFError VBA macro cell formula

    Post the formula as it is, working, in the spreadsheet. Then I/we can see what it should look like.

    Post a workbook, not pictures.

  7. #7
    Registered User
    Join Date
    09-13-2024
    Location
    San Diego
    MS-Off Ver
    11
    Posts
    9

    Re: AverageIF and IFError VBA macro cell formula

    Quote Originally Posted by TMS View Post
    Post the formula as it is, working, in the spreadsheet. Then I/we can see what it should look like.

    Post a workbook, not pictures.
    Sorry about that, I had posted it prior, but was demonstrating that it didn't work...

    Regardless, I solved the issue myself with the following, It was just syntax and sharing in case someone else has the same issues, it might help them...
    Formula: copy to clipboard
    Please Login or Register  to view this content.

+ 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: 4
    Last Post: 10-09-2021, 12:58 PM
  2. Need to pull cell formatting with an IFERROR with VLOOKUP formula
    By blinker65 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-06-2021, 04:50 PM
  3. Replies: 1
    Last Post: 06-03-2019, 07:59 AM
  4. Iferror/averageif dilemma
    By samyscraps01 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-05-2018, 06:18 PM
  5. AverageIF or Macro?
    By Benny3 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-09-2017, 12:50 PM
  6. [SOLVED] AverageIF with OR in Macro
    By aadeshgandhi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2013, 12:35 PM
  7. using Averageif in a macro
    By jkruse in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-05-2012, 12:26 PM

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