+ Reply to Thread
Results 1 to 17 of 17

COUNTIF but if Hi-Lited Don't

  1. #1
    Registered User
    Join Date
    12-11-2012
    Location
    San Mateo
    MS-Off Ver
    Excel 2016
    Posts
    16

    COUNTIF but if Hi-Lited Don't

    What I am trying to do use a statement similar to =COUNTIF(A1:A10,"X") and it will count the x's in the column. What I want to do is if the row is hi-lited I want to ignore the count, so it the count is 5 and one row is hi-lited that has an X then I want the result to be 4.

    Thanks, Dave

  2. #2
    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
    52,946

    Re: COUNTIF but if Hi-Lited Don't

    Hi and welcome to the forum

    excel cant "see" colors. what you will need to do is determine the criteria to cause the row to be high-lighted in the 1st place, and then build that criteria into your countif()...although you will probably need to use countifS() instead
    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

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: COUNTIF but if Hi-Lited Don't

    Is the row highlighted using conditional formatting? If so, you should be able to write a formula based on WHY the row is highlighted to do what you want.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Registered User
    Join Date
    12-11-2012
    Location
    San Mateo
    MS-Off Ver
    Excel 2016
    Posts
    16

    Re: COUNTIF but if Hi-Lited Don't

    Quote Originally Posted by Tony Valko View Post
    Is the row highlighted using conditional formatting? If so, you should be able to write a formula based on WHY the row is highlighted to do what you want.
    The row is being highlighted manually and the color is random but for the sake of getting this to work the color can be specific.

  5. #5
    Registered User
    Join Date
    12-11-2012
    Location
    San Mateo
    MS-Off Ver
    Excel 2016
    Posts
    16

    Re: COUNTIF but if Hi-Lited Don't

    Quote Originally Posted by FDibbins View Post
    Hi and welcome to the forum

    excel cant "see" colors. what you will need to do is determine the criteria to cause the row to be high-lighted in the 1st place, and then build that criteria into your countif()...although you will probably need to use countifS() instead
    The row is high-lighted manually depending on the situation. I'll look into using countifs, that is a new one for me.

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: COUNTIF but if Hi-Lited Don't

    As FDibbins noted, Excel can't "see" color when calculating a formula.

    When you change a cell format (color) that action does not trigger a calculation so a formula based on a cells color will not update until some event causes a calculation (or if you force a manual calculation).

    For that reason I advise against basing formulas on cell formats (color).

    If you insist on doing it that way then you'll need a VBA procedure. See this:

    http://www.cpearson.com/Excel/colors.aspx

  7. #7
    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
    52,946

    Re: COUNTIF but if Hi-Lited Don't

    the countifS() will still ONLY work if you can come up with a rule to determine when the row would get high-lighted, so you need to work on that.

    If the situation is just a...hmmm I think I will color this row - and that 1 over here...then excel will have no way of identifying why you chose those 2 rows

  8. #8
    Registered User
    Join Date
    12-11-2012
    Location
    San Mateo
    MS-Off Ver
    Excel 2016
    Posts
    16

    Re: COUNTIF but if Hi-Lited Don't

    Quote Originally Posted by Tony Valko View Post
    As FDibbins noted, Excel can't "see" color when calculating a formula.

    When you change a cell format (color) that action does not trigger a calculation so a formula based on a cells color will not update until some event causes a calculation (or if you force a manual calculation).

    For that reason I advise against basing formulas on cell formats (color).

    If you insist on doing it that way then you'll need a VBA procedure. See this:

    http://www.cpearson.com/Excel/colors.aspx
    I'll read it over but I'm not a VBA guy but it may turn me into one. Thanks for steering me in a direction.

  9. #9
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: COUNTIF but if Hi-Lited Don't

    Thanks for the feedback. Good luck!

  10. #10
    Registered User
    Join Date
    12-11-2012
    Location
    San Mateo
    MS-Off Ver
    Excel 2016
    Posts
    16

    Re: COUNTIF but if Hi-Lited Don't

    If I succeed I'll post the findings/results

  11. #11
    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
    52,946

    Re: COUNTIF but if Hi-Lited Don't

    Also, please do not use "reply with quotes" when responding to a previous thread unless there is a specific point you wish to high-light. It serves no other purpose that to clutter up the screen and waste space.

    Thanks

  12. #12
    Registered User
    Join Date
    12-11-2012
    Location
    San Mateo
    MS-Off Ver
    Excel 2016
    Posts
    16

    Re: COUNTIF but if Hi-Lited Don't

    The following VBA does exactly what I want:

    Public Function Ccolor(rng As Range, reference As Variant) As Integer
    Application.Volatile
    Dim cell As Range
    Dim val As Integer
    val = 0
    For Each cell In rng
    If cell.Interior.Color <> vbYellow And cell.Value = reference Then
    val = val + 1
    End If
    Next cell
    Ccolor = val
    End Function

    So instead of Using COUNTIF use Ccolor and it will work with a yellow highlight.

  13. #13
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: COUNTIF but if Hi-Lited Don't

    Good deal. Thanks for letting us know!

  14. #14
    Forum Expert Kevin UK's Avatar
    Join Date
    12-07-2010
    Location
    Radstock, Somerset
    MS-Off Ver
    365
    Posts
    1,922

    Re: COUNTIF but if Hi-Lited Don't

    @ JOB Dave

    See the forum Rules on cross posting and at least post a link!


    http://windowssecrets.com/forums/sho...Hi-Lited-Don-t

    Nice bit of code that guy gave you, how about a credit to them!
    Last edited by Kevin UK; 04-13-2013 at 06:38 PM.
    Regards Kevin


    Merged Cells (They are the work of the devil!!!)

  15. #15
    Registered User
    Join Date
    12-11-2012
    Location
    San Mateo
    MS-Off Ver
    Excel 2016
    Posts
    16

    Re: COUNTIF but if Hi-Lited Don't

    Sorry, credit Maudibe on Windows Secrets Lounge. I didn't think it was allowed to post links but since I see it done next time I'll get in trouble for doing so.
    Last edited by JOB Dave; 04-13-2013 at 06:59 PM.

  16. #16
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: COUNTIF but if Hi-Lited Don't

    Cross posting is allowed (frowned upon, but allowed), but if you do not state that your are cross posting (and supply links), that is what gets you into trouble, see rule #8 HERE
    A picture may be worth a thousand words, BUT, a sample Workbook is worth a thousand screenshots!
    -Add a File - click advanced (next to quick post), scroll to manage attachments, click, select add files, click select files, select file, click upload, when file shows up at bottom left, click done (bottom right), click submit
    -To mark thread Solved- go top of thread,click Thread Tools,click Mark as Solved
    If you received helpful response, please remember to hit the * of that post

  17. #17
    Valued Forum Contributor Maudibe's Avatar
    Join Date
    12-21-2016
    Location
    USA
    MS-Off Ver
    2010-2013
    Posts
    326

    Re: COUNTIF but if Hi-Lited Don't

    Thank you,

    Maud

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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