Hi, first post here. I've only been using VBA a few days (I've had a few things come up and it seemed like macros might be useful to learn) so I'm extremely basic. So this might be embarrassingly wrong.
I have devised the below...
Sub InsBl()
Dim LR As Long, i As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
For i = LR To 3 Step -1
If Range("B" & i).Value <> Range("B" & i - 1).Value Then Rows(i).Insert
Next i
End Sub
Sub InsertSubtotals()
Dim ThisCell As Range
Dim MySum As Double
Set ThisCell = Range("e2").Formula = "+SUMIFS(E:E,A:A,A2,B:B,B2)"
nxt:
Do While ThisCell <> ""
MySum = MySum + ThisCell
Set ThisCell = ThisCell.Offset(1, 0)
Loop
ThisCell.Value = MySum
If ThisCell.Offset(1, 0) <> "" Then
Set ThisCell = ThisCell.Offset(1, 0)
MySum = 0
GoTo nxt
End If
End Sub
...the idea is that the first part of the code opens up a new row everytime the data in column B changes; that works fine. The next step is that once the break in row happens, the formula "+SUMIFS(E:E,A:A,A2,B:B,B2)" comes in. A2 and B2 being representative, but it would be the bottom row of the column B group above. This I cannot get to work. Currently an object is required? I think I might be misunderstanding how the loop works.
So effectively it would be...
Fund Heading Supplier Date Amount
A B dave 01/01/2016 10
A B dave 02/01/2016 10
A B dave 03/01/2016 10
A E brian 01/01/2016 20
A E brian 02/01/2016 20
A H dave 01/01/2016 25
A H brian 01/01/2016 600
A H charlie 01/01/2016 50
A X ormerods 01/01/2016 200
...Where the first sumif is taking Fund A & Heading B, the second taking Fund A & Fund E etc.
Any help would be useful if anybody could have a look over. Thank you guys.
Bookmarks