TypeError: Cannot read properties of null (reading ‘getformula’)

function countColoredCells(countRange, colorRef) {

    var activeRange = SpreadsheetApp.getActiveRange();

    var activeSheet = SpreadsheetApp.getActiveSheet();

    var activeformula = activeRange.getformula();

    var countRangeAddress = activeformula.match(/((.*),/).pop().trim();

    var backGrounds = activeSheet.getRange(countRangeAddress).getBackgrounds();

    var colorRefAddress = activeformula.match(/,(.*))/).pop().trim();

    var BackGround = activeSheet.getRange(colorRefAddress).getBackground();

    var countColorCells = 0;

    for (var i = 0; i < backGrounds.length; i++)

    for (var k = 0; k < backGrounds[i].length; k++)

        if (backGrounds[i][k] == BackGround)

            countColorCells = countColorCells + 1;

    return countColorCells;

};

trying to count cells by color and this is the error
how to solve this problem pls