On the Insert menu, select Module to create a module. Open Microsoft Excel, then press Alt+F11 to show the Visual Basic Editor (VBE) window. Here are the steps to create a UDF to count cell color: Using VBA, a User Defined Function (UDF) can be created and saved into an add-in file so that it can be used in other workbooks and transferred to other computers. However, using VBA we can create a function to count the number of cells with other criteria, such as cell color.
Criteria for that function are limited to text or numbers. On the Microsoft Excel Formulas tab, we know that in the More Functions > Statistical category there is a function called COUNTIF which counts the number of cells within a range that meet a given condition.
Count the number of cells with a specific cell color using VBA