+ Reply to Thread
Results 1 to 2 of 2

VBA to count colored cells in a range

  1. #1
    Registered User
    Join Date
    03-01-2020
    Location
    Paris
    MS-Off Ver
    Office 2016
    Posts
    28

    VBA to count colored cells in a range

    Hello All,

    I used a macro count the number of colored or formatted cells in a columns

    Function CountColorIf(bArea As Range) As Long
    Dim bAreacell As Range
    Dim fillcolor As Long
    Dim colorcount As Long
    colorcount=0
    For Each bAreacell In bArea
    If bAreacell.Interior.Color <>XlNone Then
    colorcount = colorcount + 1
    End If
    Next bAreacell
    CountColorIf = colorcount
    End Function

    However when I run this formula it returns the count of entire selected columns in a row rathern than the colored or that has any formatting in it.

    Can someone help me fix this code ?

    Thanks,
    Shyam

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: VBA to count colored cells in a range

    Please use CODE tags around code when you are posting. I think you could use this slightly amended function:

    Please Login or Register  to view this content.
    WBD
    Office 365 on Windows 11, looking for rep!

+ 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. UDF to count colored cells always gives zero
    By capson in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-04-2015, 02:01 PM
  2. How to count colored cells per each cell range?
    By gabrielemucho in forum Excel General
    Replies: 4
    Last Post: 10-21-2014, 07:31 AM
  3. Replies: 1
    Last Post: 11-09-2013, 02:43 AM
  4. COUNT (or SUM?) colored cells
    By beanpoddy in forum Excel General
    Replies: 2
    Last Post: 03-27-2012, 01:14 PM
  5. Don't Count Cells Colored Red
    By scotfitz in forum Excel General
    Replies: 1
    Last Post: 04-20-2008, 04:19 PM
  6. Count colored cells?
    By mlk in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-30-2007, 06:30 PM
  7. count colored cells?
    By DKY in forum Excel Formulas & Functions
    Replies: 21
    Last Post: 01-19-2006, 05: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