Developing the formula should not be difficult, but to help give a precise answer, please upload a sample workbook (sensitive data removed) that EXACTLY duplicates the structure of your real workbook, contains a few rows of data and shows a few examples of the expected results to help with validating the results of the formula.