+ Reply to Thread
Results 1 to 9 of 9

Counting Cells by Color then by Text

  1. #1
    Registered User
    Join Date
    12-06-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Counting Cells by Color then by Text

    So I'm trying to get a count on all cells that are a specifc color and then have specific text in them. Like all cells highlighted green and have the word fiber in it. I have a vba code for counting colors, but I don't know how to tie that into counting the specific text. Any help??

    This was the code I had for counting colored cells:

    Function CountColor(rColor As Range, rSumRange As Range)
    ''''''''''''''''''''''''''''''''''''''
    'Written by Ozgrid Business Applications
    'www.ozgrid.com
    'Counts cells based on a specified fill color.
    '''''''''''''''''''''''''''''''''''''''
    Dim rCell As Range
    Dim iCol As Integer
    Dim vResult
    iCol = rColor.Interior.ColorIndex
    For Each rCell In rSumRange
    If rCell.Interior.ColorIndex = iCol Then
    vResult = vResult + 1
    End If
    Next rCell
    CountColor = vResult
    End Function

    Thanks!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Counting Cells by Color then by Text

    Perhaps.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    12-06-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Counting Cells by Color then by Text

    Nope unless I'm doing something wrong.. I switched that in the code, and selected the exact cell I wanted to be counted for rColor, but I just get zero now.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Counting Cells by Color then by Text

    Did you change "TextToCheckFor" to whatever text you want to check for?

  5. #5
    Registered User
    Join Date
    12-06-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Counting Cells by Color then by Text

    Oh no ha. But I just did and I'm stilling getting zero. Is there anything else I needed to change?

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Counting Cells by Color then by Text

    No.

    Are you sure there are cells which match the criteria?

    Does it work for colour on it's own?

    Can you attach a sample workbook?

  7. #7
    Registered User
    Join Date
    12-06-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Counting Cells by Color then by Text

    The editted does not count just the color either. But I'll attach a sample. I want where it says "Total Coax Billing Sites" to tell me how many customer names are green and say "1 Coax". And "Total Fiber Billing Sites" to tell me how many are green and say either "existing fiber hub" or "new fiber hub".
    Attached Files Attached Files

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Counting Cells by Color then by Text

    This isn't going to help if it's '1 Coax' you want to count.
    Please Login or Register  to view this content.
    Try this.
    Please Login or Register  to view this content.
    You would use it like this.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    I'm afraid it only deals with exact matches so you might need 2 formulas for the 'fiber' count.

  9. #9
    Registered User
    Join Date
    12-06-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Counting Cells by Color then by Text

    That's completely fine, it works great! Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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