'Implementing an Excel nested function or VBA code for numbering a table

I need to write some VBA code which could give me the result in the "Sorted Numbering" column in the below picture:

Sorting

The logic for the sorting is that filter the first value based on Column1 then filter the second value based on Column2. If the values are duplicate (or triplicate or quadruplicate) then check Column3. If the dates are different then mention "1" in the Sorted Numbering column for the oldest date, then 2 against the second oldest date, then 3 against the third oldest date etc.

If the dates are the same for the duplicate values then check the sequence in Column4 and mention 1 the Sorted Numbering column for the lowest number, then 2 for the next lowest number and so. Where ever the values in Column1 and Column2 are unique (example row number 5) then mention NA in the Sorted Numbering column.

How can I do this using looped/nested functions in Excel. Or do we need to use VBA for this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source