+ Reply to Thread
Results 1 to 6 of 6

Counting coloured cells

Hybrid View

  1. #1
    Registered User
    Join Date
    10-24-2012
    Location
    Guelph, ON
    MS-Off Ver
    Excel 2010
    Posts
    41

    Counting coloured cells

    Hi: I've been looking through various threads and other sites and can't figure this one out. I'm trying to count cells in a column based on their font colour which are defined by conditional formatting in the spreadsheet. I'm using 2010 and think that maybe the macro I'm trying to use won't work in 2010.

    In column R from R9 to the last row (which I put "end" into) I want to count colour coded dates that are for previous, current and future months. Future dates are in red, current are black and previous are blue. I want to return the counts in cells V2, V3, V4. Hopefully that makes sense??

    My current macro will return the full count in V3 which is "black". So it's not differentiating the colours. I've also attached a sample file with our sensitive data deleted. Here is what I have:

    Sub Color()

    Dim previous As Integer
    Dim future As Integer
    Dim current As Integer

    Range("r9").Select
    future = 0
    current = 0
    previous = 0

    Do Until Selection.Value = "end"
    If Selection.Font.Color = RGB(255, 0, 0) Then
    future = future + 1
    End If
    Selection.Offset(1, 0).Select
    Loop

    Range("r9").Select
    Do Until Selection.Value = "end"
    If Selection.Font.Color = RGB(0, 0, 255) Then
    previous = previous + 1
    Else
    current = current + 1
    End If
    Selection.Offset(1, 0).Select
    Loop

    Range("v2").Select
    Selection.Value = future

    Range("v3").Select
    Selection.Value = current

    Range("v4").Select
    Selection.Value = previous

    End Sub

    Any suggestions or help would be greatly appreciated!
    Thanks!!! Stef.
    Attached Files Attached Files

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Counting coloured cells

    why not just use countif based on the condition formulas?
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Registered User
    Join Date
    10-24-2012
    Location
    Guelph, ON
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Counting coloured cells

    Oh boy... sometimes the answers are so simple! Although I think I must be having trouble with the date format. The spreadsheet is downloaded with tons of data from another source and dumped into excel. I didn't think that should make a difference, but for somereason I can't get the countif to work. I should be able to reference a cell, but it is not working. For example if I enter =countif(R9:R200,">R2") where R2 has a date (eg. 1-FEB-13) it should count all the cells whose datevalue is greater than 1-feb-13. However, I can only get it to work if I enter =countif(R9:R200,">41306") where 41306 is the value of Feb 1. Any ideas on that?? It's weird because I've not had that trouble in other spreadsheets.

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Counting coloured cells

    it needs to be =countif(R9:R200,">"&R2)

  5. #5
    Registered User
    Join Date
    10-24-2012
    Location
    Guelph, ON
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Counting coloured cells

    Thank you!!! That worked. Appreciate the help and that it was a much simpler solution than expected!!!!

  6. #6
    Registered User
    Join Date
    10-24-2012
    Location
    Guelph, ON
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Counting coloured cells

    Thank you!!! That worked. Appreciate the help and that it was a much simpler solution than expected!!!! OH, and you were much more helpful than the help function right out of excel!!

+ 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