+ Reply to Thread
Results 1 to 7 of 7

How to Count Highlighted Rows that contain an X ?

Hybrid View

  1. #1
    Registered User
    Join Date
    11-16-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    3

    Question How to Count Highlighted Rows that contain an X ?

    Hi All,

    To find the best product for my customers I need to count the rows that I have highlighted by filling with a colour AND that contain an 'X' in the cell. Giving a total at the bottom of the row for each highlighted and 'X' cell. I cannot find any easy way of doing this and I am sure I will need to run a VBA script but cant quite get my head around how to do this. Perhaps there is an easier way to do this entirely! I'm open to all suggestions.

    I have attached a picture of what it currently looks like.

    CountHighlightedXRows.jpg

    Many thanks

    Sean

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: How to Count Highlighted Rows that contain an X ?

    Formula: copy to clipboard
    =COUNTIF(A1:B10,"x")


    Adapt the range reference to your range.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    11-16-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: How to Count Highlighted Rows that contain an X ?

    Ok i have the following code to count the highlighted cells (thanks to an earlier post today) now i need to add AND contains 'X'

    Function Count_Highlights(rng As Range)
    Dim CCell As Range, x As Long
    x = 0
    For Each CCell In rng.Cells
       If CCell.Interior.Color <> 16777215 And CCell.Interior.Color <> xlNone Then x = x + 1
    Next CCell
    Count_Highlights = x
    End Function
    Thanks Sixthsense, but i have two requirements: count cells that are highlighted AND contain x

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: How to Count Highlighted Rows that contain an X ?

    Hm... If you want to count based on the background color and value "x" then slight changes in your UDF.

    Function Count_Highlights(myRng As Range)
    Dim x As Long, c As Variant
    
    For Each c In myRng
        If c.Interior.ColorIndex = 48 And c.Value = "x" Then x = x + 1
    Next c
    
    Count_Highlights = x
    
    End Function
    To know the active cell background color Number then use the below code

    Sub GetActivecellBackgroundColorIndex()
    
    MsgBox ActiveCell.Interior.ColorIndex
    
    End Sub

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: How to Count Highlighted Rows that contain an X ?

    Six's solution will give you a count of the "X", but as far as I know, there is no formula to count "colors".

    is there some logic to them being colored that excel could use to assist the count?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  6. #6
    Registered User
    Join Date
    11-16-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: How to Count Highlighted Rows that contain an X ?

    Thank you very much!!
    This is the final code that worked for me..

    Function Count_Highlights(rng As Range)
    Dim CCell As Range, x As Long
    x = 0
    For Each CCell In rng.Cells
       If CCell.Interior.Color <> 16777215 And CCell.Interior.Color <> xlNone And CCell.Value = "x" Then x = x + 1
    Next CCell
    Count_Highlights = x
    End Function
    Many many thanks.

  7. #7
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: How to Count Highlighted Rows that contain an X ?

    Glad you solved it on your own

+ 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