Consulting

Results 1 to 3 of 3

Thread: Excel - Colourfunction

  1. #1

    Excel - Colourfunction

    Hi Guys,

    May I know whether is there such function in excel whereby I will be able to track the number of coloured cells and sum it?

    For example:
    A1 - green coloured cell
    A2 - orange coloured cell
    A3 - green coloured cell
    A4 - purple coloured cell
    A5 - green coloured cell
    A6 - purple coloured cell

    Count
    green = 3
    orange = 1
    purple = 2

    I do know there is such function COUNTIF(A1: A6), but nt too sure hw to continue from there. Any help will be much appreciated.

  2. #2
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    I dont know of a function in excels frontend that will do this, you could use a loop in vba to count the cell colours.

    Sub Macro1()
    Dim MyRange As Range, rCell As Range
    Dim red, orange, green As Integer
    Set MyRange = Range("A1:A50")
    For Each rCell In MyRange.Cells
        If rCell.Interior.Color = 255 Then red = red + 1
        If rCell.Interior.Color = 49407 Then orange = orange + 1
        If rCell.Interior.Color = 5287936 Then green = green + 1
    Next
    MsgBox "There are " & red & " red cells." & vbNewLine & "There are " & orange & " orange cells." _
    & vbNewLine & "There are " & green & " green cells."
    End Sub
    you would need to change the range that has been set and the colours that have been used to suit.

    I use Excel 2007 so i believe that the colour index's asr different

    Hope this helps
    Last edited by Aussiebear; 04-27-2023 at 03:36 AM. Reason: Adjusted the code tags
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •