webForumDet fria alternativet

Räkna celler med bakgrundsfärg

Kontorsprogram

2 svar · 381 visningar · startad av Web-Tor

Medlem sedan nov. 200013 890 inlägg
Frågan#1

Kan man i Excel räkna alla celler i en kolumn som har en viss bakgrundsfärg?

Medlem sedan sep. 2006284 inlägg
#2

Javisst - med VBA

Function CountByColor(InRange As Range, _
    WhatColorIndex As Integer, _
    Optional OfText As Boolean = False) As Long
'
' This function return the number of cells in InRange with 
' a background color, or if OfText is True a font color, 
' equal to WhatColorIndex.
'
Dim Rng As Range
Application.Volatile True

For Each Rng In InRange.Cells
If OfText = True Then
    CountByColor = CountByColor -  _ 
            (Rng.Font.ColorIndex = WhatColorIndex)
Else
    CountByColor = CountByColor -  _ 
       (Rng.Interior.ColorIndex = WhatColorIndex)
End If
Next Rng

End Function

You can call this function from a worksheet cell with a formula like
=COUNTBYCOLOR(A1:A10,3,FALSE)

http://www.cpearson.com/excel/colors.htm

.. och om CF har använts: http://www.cpearson.com/excel/CFColors.htm

Medlem sedan nov. 200013 890 inlägg
#3

Oj! :o

243 ms totalt · 4 externa anrop · v20260731065814-full.a51de22e
120 ms — deklarationer (db)
0 ms — hämta statistik (cache)
119 ms — hämta tråd, inlägg och bilagor (db)
121 ms — ändringar (db)