Results 1 to 4 of 4

userform to count cell colours and display in textboxes

Threaded View

  1. #1
    Registered User
    Join Date
    06-23-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    57

    Question userform to count cell colours and display in textboxes

    Hey all,

    I have a tracker that displays employee holiday/sickness absence throughout the year (indicated by specific colours).

    I have a userform that I want to count the number of these specific colours per employee.

    I have a attached an example of the workbook:

    Basically, I want to be able to select an employee from the combobox1 and it automatically calculate the number of holiday days, sick days or other days the employee has taken throughout the year by counting the colour filled cells..

    I found a few code examples that do something similar but require cells to have formula's in them, I'd really like to keep this to the userform rather than cells on the worksheet. Can the following code (which i found on this site) be modified to suit my needs or will i need something more bespoke?

    Function CountByColor(InputRange As Range, ColorRange as Range) As Long
    Dim cl As Range, TempCount As Long, ColorIndex As Integer
        ColorIndex = ColorRange.Cells(1, 1).Interior.ColorIndex
        TempCount = 0
        For Each cl In InputRange.Cells
            If cl.Interior.ColorIndex = ColorIndex Then 
                TempCount = TempCount + 1
            End If
        Next cl
        Set cl = Nothing
        CountByColor = TempCount
    End Function
    Any help is massively appreciated.

    Adam

    PS: I've asked this question on MrExcel too, i will keep them both updated with responses.

    http://www.mrexcel.com/forum/showthr...08#post2666808
    Attached Files Attached Files
    Last edited by AGrace; 03-31-2011 at 09:39 AM.

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