ALT+F11,打开VBA窗口,左侧鼠标右击“Thisworkbook”,新建模块module,然后右边窗口粘入以下代码: Function Countcolour(rng As Range, colour As Range) As Long Dim c as Range Application.Volatile For Each c In rng If c.Interior.ColorIndex = colour.Interior.ColorIndex Then Countcolour = Countcolour + 1 End If Next End Function