```
Sub test2()
With Worksheets("Sheet2") ' input sheet
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row ' find last row of col A
inarr = .Range(.Cells(1, 1), .Cells(lastrow, 3)) ' load coluimns A , b and C into varaint array
End With
With Worksheets("Sheet3") ' swap to output sheet
.Range(.Cells(1, 5), .Cells(20 * lastrow, 6)) = "" ' clear the output range
outarr = .Range(.Cells(1, 5), .Cells(20 * lastrow, 6)) ' load the output array from the worksheet ensur it is all clear
indi = 0 ' set outpt index to zero
mon = 0 ' set month number to zero
sumt = 0 ' set monthly sum to zero
monstart = 2
For i = 2 To lastrow ' loop through all the input rows
If inarr(i, 1) <> "DAILY TOTALS" And inarr(i, 2) <> "" Then ' check if it is arow we don't copy
' copy the row
If IsNumeric(inarr(i, 3)) Then ' check if the month numberr is numeric
If inarr(i, 3) <> mon Then ' check if we have got to the next month
If mon <> 0 Then ' check if we have process one month , if we have put in the totals
If mon = 2 Then
outarr(indi, 1) = "Total" ' add text to output row
outarr(indi, 2) = sumt ' add total to output row
indi = indi + 1 ' skip a row
End If
sumt = 0 ' reset the sum to zero
End If
indi = indi + 1 ' increment the output row count
outarr(indi, 1) = MonthName(inarr(i, 3)) & " TOTALS" ' output month name and text to next row
mon = inarr(i, 3) ' set the current month to the new month
indi = indi + 1 ' increment the output row
monstart = indi
End If
addto = False
For kk = monstart To indi
If inarr(i, 1) = outarr(kk, 1) Then
outarr(kk, 2) = outarr(kk, 2) + inarr(i, 2)
addto = True
Exit For
End If
Next kk
If Not (addto) Then
For j = 1 To 2 ' copy the column A and b to output
outarr(indi, j) = inarr(i, j)
Next j '
indi = indi + 1 ' increment the row
End If
sumt = sumt + inarr(i, 2) ' add the current value to the sum
End If
End If
Next i
If mon = 2 Then
outarr(indi, 1) = "Total" ' put int the totals for the last month
outarr(indi, 2) = sumt '
indi = indi + 1 ' increment the row count actually I don't think we need this!!
End If
.Range(.Cells(1, 1), .Cells(2 * lastrow, 2)) = outarr 'output the array to the workhseet
End With
End Sub
```