Excel VBA to Create Subtotals on the Fly

In Excel you can make a subtotal with the help of VBA, so the totals are generated automatically. I have found occasions where I have wanted to perform a subtotal but I did not want to use Excel’s inbuilt Subtotal feature as the data was a different size and shape each time. I wanted to have a bit more control over the look and feel of the end product than Excel's inbuilt Subtotal function. So I created a procedure which will produce a Sum on the fly, where like items are grouped together and a subtotal for each group of items is produced. Here is a screen shot of the procedure before it is run.

The following is what the file looks like after the procedure has run.

This can be done with the following code;

Option Explicit

Sub aSubTotal() 'Excel VBA to create subtotals.Dim iCol As IntegerDim i As IntegerDim j As Integer