I have a range (the image below).

Please note that:

- Range is generated by another application, so number of rows is ever changing, and is not formatted as an Excel 'table'
- The number of columns, however, is fixed.
- There is always a
`Totals`

row, which is always the last row (cells beyond this however contains formula evaluating to '')

I want help with a VBA Macro that will sort the range using header `D`

as key (ascending):

[See link to the sorted table below]

Please note that:

- The
`Totals`

row (which is always the last row) should be ignored and not sorted.

After this sort, I want the same VBA Macro to apply conditional formatting to the range using the same header `D`

as key - the formatting applies a border around the range where `D`

is the same:

Final table is here: http://goo.gl/H118Lx

Please note that:

- I don't want border around unique values in header
`D`

i.e rows where the cell-value-count is not greater than 1.