The COUNTIF function in Excel counts the number of cells that meet certain criteria within a specific range.