Page 1 of 2 12 LastLast
Results 1 to 10 of 12

COUNTING A HIGHLIGHTED CELL

This is a discussion on COUNTING A HIGHLIGHTED CELL within the Excel Questions forums, part of the Question Forums category; I am very new to excel. I have a list of products that my staff highlights and then forwards to ...

  1. #1
    New Member
    Join Date
    Aug 2003
    Posts
    17

    Default COUNTING A HIGHLIGHTED CELL

    I am very new to excel.
    I have a list of products that my staff highlights and then forwards to me for approval....my question is ...is there any way that i can have the highlighted cells be counted automatically?....

    say i highlight 15 cells in red,

    can excel count all the highlighted cells?

  2. #2
    Board Regular Todd Bardoni's Avatar
    Join Date
    Aug 2002
    Location
    Rochester, MI USA
    Posts
    3,044

    Default Re: COUNTING A HIGHLIGHTED CELL

    How about:-
    Code:
    Sub Test()
        For Each cell In Sheets("Sheet1").UsedRange
            If cell.Interior.ColorIndex = 3 Then i = i + 1
        Next cell
        MsgBox "There are " & i & " cells in red.", vbInformation
    End Sub
    Todd


    "I'm a Data Anlyst(intermediate) and have no idea what it's all about."

  3. #3
    New Member
    Join Date
    Aug 2003
    Posts
    17

    Default Re: COUNTING A HIGHLIGHTED CELL

    UHHH,,,I copied and pasted that ,but it did not work..or i donot know what i am doing,,,lol

    i am banking on the later....can you explain it in remedial terms...sorry i am excel illiterate.....

  4. #4
    Board Regular Todd Bardoni's Avatar
    Join Date
    Aug 2002
    Location
    Rochester, MI USA
    Posts
    3,044

    Default Re: COUNTING A HIGHLIGHTED CELL

    Try this:-
    Hit Alt+F11 to display the VB Editor. Then go to Insert/Module and paste this code:-
    Code:
    Sub Test()
        x = ActiveSheet.Name
        i = 0
        For Each cell In Sheets(x).UsedRange
            If cell.Interior.ColorIndex = 3 Then i = i + 1
        Next cell
        MsgBox "There are " & i & " cells in red.", vbInformation
    End Sub
    Todd


    "I'm a Data Anlyst(intermediate) and have no idea what it's all about."

  5. #5
    Board Regular Corticus's Avatar
    Join Date
    Apr 2002
    Location
    Sarasota, FL
    Posts
    1,552

    Default Re: COUNTING A HIGHLIGHTED CELL

    Hi MONNGO69,

    By doing what tbardoni suggested you can paste the following function into a module:
    Code:
    Function ct_fill(rng As Range) As Integer
    
        Dim cl As Range
    
        ct_fill = 0
        
        For Each cl In rng
            If cl.Interior.ColorIndex <> xlNone Then
                ct_fill = ct_fill + 1
            End If
        Next cl
    
    End Function
    and use like this:
    ******** ******************** ************************************************************************>
    Microsoft Excel - count_fill.xls___Running: xl2000 : OS = Windows XP
    (F)ile (E)dit (V)iew (I)nsert (O)ptions (T)ools (D)ata (W)indow (H)elp (A)bout
    =

    A
    B
    C
    D
    1
    *Entry**
    2
    *Entry1**
    3
    *Entry2**
    4
    *Entry3**
    5
    *Entry4**
    6
    *Entry5**
    7
    *Entry6**
    8
    *Entry7**
    9
    *Entry8**
    10
    *Entry9**
    11
    *Entry10**
    12
    shaded*entries:4**
    Sheet1*

    [HtmlMaker 2.42] To see the formula in the cells just click on the cells hyperlink or click the Name box
    PLEASE DO NOT QUOTE THIS TABLE IMAGE ON SAME PAGE! OTHEWISE, ERROR OF JavaScript OCCUR.


    Hope this helps,
    Corticorp, LLC
    -Development Solutions for .NET, Java, PHP, HTML5, iPad/iPhone, Android and many more
    -Database Development for SQL Server, MySQL, Oracle and others
    http://www.corticorp.com

  6. #6
    New Member
    Join Date
    Oct 2003
    Posts
    1

    Default Re: COUNTING A HIGHLIGHTED CELL

    go to http://www.xl-logic.com/pages/vba.html
    and download count_colors.zip

    Regards
    J (who is equally excel challenged)

  7. #7
    Board Regular Iridium's Avatar
    Join Date
    Jul 2002
    Location
    West Bridgford, Notts., England
    Posts
    2,834

    Default Re: COUNTING A HIGHLIGHTED CELL

    Iridium


  8. #8
    New Member
    Join Date
    Aug 2003
    Posts
    17

    Default Re: COUNTING A HIGHLIGHTED CELL

    Hey all thanks for the help.

    But when i try any of them i get a compile error expected end sub?????


    any ideas?...

    or am i doing it wrong?...

  9. #9
    MrExcel MVP
    Join Date
    Apr 2002
    Location
    Vancouver BC , Canada
    Posts
    6,259

    Default Re: COUNTING A HIGHLIGHTED CELL

    Sub CountColor()
    For Each Cel In Cells.SpecialCells(xlCellTypeConstants, 3)
    If Not Cel.Interior.ColorIndex = 0 Then Count = Count + 1
    Next Cel
    pt = MsgBox("The number of cells highlighted is : " & Count)
    End Sub

    TO INSTALL:
    1. Select the sheet you would like to count
    2. Right click on the sheets "Name Tab"
    3. Select "veiw code" from drop down menu
    4. VBE window will open
    5. Paste the above code into the VBE window and close window

    <MARQUEE>...........Never be afraid to try something new. Remember, amateurs built the ark, professionals built the Titanic...............The easiest thing to find is fault, don't be easy !.. --Anonymous--...</marquee>

  10. #10
    MrExcel MVP
    Join Date
    Apr 2002
    Location
    Vancouver BC , Canada
    Posts
    6,259

    Default Re: COUNTING A HIGHLIGHTED CELL

    VERSION 2:

    This version error traps if no cells have any values

    Sub CountColor()
    On Error GoTo NoCount
    For Each Cel In Cells.SpecialCells(xlCellTypeConstants, 3)
    If Not Cel.Interior.ColorIndex = 0 Then Count = Count + 1
    Next Cel
    pt = MsgBox("The number of cells highlighted is : " & Count)
    Exit Sub
    NoCount:
    pt = MsgBox("No cells found to count")
    End Sub

    <MARQUEE>...........Never be afraid to try something new. Remember, amateurs built the ark, professionals built the Titanic...............The easiest thing to find is fault, don't be easy !.. --Anonymous--...</marquee>

Page 1 of 2 12 LastLast

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
  •  


DMCA.com