+ Reply to Thread
Results 1 to 11 of 11

SumByColour displays #VALUE!

  1. #1
    Registered User
    Join Date
    12-05-2023
    Location
    North West, England
    MS-Off Ver
    Office 16
    Posts
    6

    SumByColour displays #VALUE!

    Hi,

    I was wondering if anyone could help please. I have a spreadsheet and I am trying to sum by colour based on the colour of the cells that is defined by conditional formatting. I am not even close to being an expert so have cobbled some VBA code together by research on google.

    I am so close when I look at the result in the insert function it gives me the number I am after but when displayed in the spreadsheet I am getting #VALUE! see images, all values are formatted as a number with no spaces etc.

    The VBA code used is as follows. Please help it is driving me crazy!!!! Thanks in advance

    Please Login or Register  to view this content.
    Capture.JPG
    Capture2.JPG
    Last edited by AliGW; 12-06-2023 at 04:36 AM. Reason: Code tags added - please review the forum guidelines.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: SumByColour displays #VALUE!

    Please read the yellow banner at the top of this page on how to attach a sample workbook.

  3. #3
    Registered User
    Join Date
    12-05-2023
    Location
    North West, England
    MS-Off Ver
    Office 16
    Posts
    6

    Re: SumByColour displays #VALUE!

    davesexcel. Thanks, I have uploaded an example file, cell H8 is were I am trying to sum by colour. If in cell H8 if you go to formulas>insert function you can see it is summing it up correctly but on the sheet there is a #VALUE! error.

    Many thanks in advance for any help anyone could offer, thanks.

    Example.xlsm

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: SumByColour displays #VALUE!

    Few issues here.

    1. You cannot use DisplayFormat property in User Defined functions (UDF). See link below for details.
    https://learn.microsoft.com/en-us/of....displayformat

    2. When I check Interior.ColorIndex (or Interior.Color) of G4:J6, none match that of G8. You need to make sure you use same color.

    As for your function, you can write it as...
    Please Login or Register  to view this content.
    I assumed cases where result may be decimal value.
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

  5. #5
    Registered User
    Join Date
    12-05-2023
    Location
    North West, England
    MS-Off Ver
    Office 16
    Posts
    6

    Re: SumByColour displays #VALUE!

    Thanks for your advice CK76, sorry I am a novice at this and have just been using google to get to where I am. I have tried your code and it hasn't worked. With the old code when i look at the result it displays the figure I want in the insert function but using the new code it displays 0 in the insert function.

    Colours appear to be the same but these are conditionally formatted colours so not the true cell background colours which is why I used the displayformat.

    Any further advice would be appreciated, thanks.

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,710

    Re: SumByColour displays #VALUE!

    Try it like
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    12-05-2023
    Location
    North West, England
    MS-Off Ver
    Office 16
    Posts
    6

    Re: SumByColour displays #VALUE!

    Fluff13, you are a genius!!!! Thank you so much this worked perfectly, it had been driving me crazy for weeks!!!

  8. #8
    Registered User
    Join Date
    12-05-2023
    Location
    North West, England
    MS-Off Ver
    Office 16
    Posts
    6

    Re: SumByColour displays #VALUE!

    Hi Fluff13, one last thing the code works perfectly and sums the values and displays them correctly. The only thing is if something changes it doesn't automatically update and recalculate unless you go into the formula and press return as if you have just entered the formula again? Is there any workaround so it auto updates? Thank you.

  9. #9
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,710

    Re: SumByColour displays #VALUE!

    You could add this line
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    12-05-2023
    Location
    North West, England
    MS-Off Ver
    Office 16
    Posts
    6

    Re: SumByColour displays #VALUE!

    Hi Fluff13, the added line didn't work but not to worry, I can live with it. Many thanks for all of your help.

  11. #11
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,710

    Re: SumByColour displays #VALUE!

    Glad to help & thanks for the feedback.

+ 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] d:hh:mm to displays over 31 days like [hh]:mm displays over 24 hours.
    By smit.etha in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-17-2015, 11:59 AM
  2. [SOLVED] If displays #REF then value
    By siroco79 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-13-2014, 10:01 AM
  3. [SOLVED] MSG BOX displays twice
    By delaneybob in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-13-2012, 06:04 PM
  4. Replies: 2
    Last Post: 11-02-2011, 10:55 AM
  5. No value displays a zero
    By Rodeoclown in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-08-2010, 12:16 AM
  6. 12:00 displays as 00:05 in XML
    By JanieA in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-25-2009, 11:12 PM
  7. [SOLVED] CSV c/r l/f displays as box
    By Al in forum Excel General
    Replies: 1
    Last Post: 05-17-2006, 08:50 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