简体   繁体   中英

How do I create a counta formula that only counts data in cell highlighted a specific color?

I have an attendance spreadsheet with data highlighted in 3 different colors. At the bottom of the spreadsheet I have a CountA formula to count all cells that have an 'x' imputed for a total count each day. I also need a formula that will do the same count but by the color of the highlighted cell only. This formula will also need to automatically update when data is changed or updated on the spreadsheet. I am quite familiar with Excel but I have very little experience with creating VGA's and have not had any luck with creating one that works at this time.

This will feel a bit overwhelming if you are not experienced with VBA, but there are a few questions and answers already on SO -- see here or here .

Regardless, have you considered using "Filter by Color" as an alternative? Use Data > Filter and then choose Filter by Color . Once filtered, you should find a nifty count in the lower-left corner of the Excel window.

图片01

图片02

图片03

you could try this. the following code asks for a cell reference for input (to receive the color to search for) counts how many cells found with the specified color into a specific range. and returns the counted number into a messagebox.

Sub Color()
    Dim colorCount, colorVal As Double
    Dim rng, cell As Range

    colorCount = 0
    Set rng = Application.InputBox(prompt:="Write a cell address that already has the desired color.(e.g.:A1)", Title:="Define the color.", Type:=8)
    colorVal = Cells(rng.Row, rng.Column).Interior.Color
    For Each cell In Range("a1:a5")
        If cell.Interior.Color = colorVal Then
            colorCount = colorCount + 1
        End If
    Next
    MsgBox colorCount
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM