Using VBA (Custom Function): Open VBA Editor: Press Alt + F11. Insert Module: Go to "Insert" > "Module". Paste Code: Paste the following VBA code into the module: Close VBA Editor: Return to Excel. Use the Function: In a cell, Use the formula =CountColoredCells(range_to_check, cell_with_target_color).