Hey so the macro works okay but unfortunately I forgot to put in the sample the possibility of having more than one type of the same spending. The attached workbook makes up for this problem.
The current Macro would combine all lines based off the Type of Spending, not the combination of the two (Type of Spending and Dept). I was thinking maybe a SUMIFS instead of the SUMIF, but unfortunately I am on Office2004 and they don't have the SUMIFS.
2 Questions: If I were to be able to use a Windows machine and the SUMIFS statement on excel 07/10 would the following command work (and then replace the rest of the Range formulas..
2nd: What is a good workaround of SUMIFS for older versions of excel? (Question 1 is more important, I am trying to get the new windows version but it isn't that easy)
Range("M2").Formula = "SUMIFS($C$2:C$" & LastRow & ",$A$2:$A$" & LastRow & ",$A2,$B$2:$B$" & LastRow & ",$B2)"
Here is the original code that I formatted for 10 columns of quarter data
Sub SumThenReduceList()
Dim LastRow As Long, RowNo As Long
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Columns("A:L").Sort Key1:=Worksheets("Sheet1").Range("B1"), _
Key2:=Worksheets("Sheet1").Range("A1"), Header:=xlYes
Range("M2").Formula = "=SUMIF($A$2:$A$" & LastRow & ",$A2,$C$2:$C$" & LastRow & ")"
Range("N2").Formula = "=SUMIF($A$2:$A$" & LastRow & ",$A2,$D$2:$D$" & LastRow & ")"
Range("O2").Formula = "=SUMIF($A$2:$A$" & LastRow & ",$A2,$E$2:$E$" & LastRow & ")"
Range("P2").Formula = "=SUMIF($A$2:$A$" & LastRow & ",$A2,$F$2:$F$" & LastRow & ")"
Range("Q2").Formula = "=SUMIF($A$2:$A$" & LastRow & ",$A2,$G$2:$G$" & LastRow & ")"
Range("R2").Formula = "=SUMIF($A$2:$A$" & LastRow & ",$A2,$H$2:$H$" & LastRow & ")"
Range("S2").Formula = "=SUMIF($A$2:$A$" & LastRow & ",$A2,$I$2:$I$" & LastRow & ")"
Range("T2").Formula = "=SUMIF($A$2:$A$" & LastRow & ",$A2,$J$2:$J$" & LastRow & ")"
Range("U2").Formula = "=SUMIF($A$2:$A$" & LastRow & ",$A2,$K$2:$K$" & LastRow & ")"
Range("V2").Formula = "=SUMIF($A$2:$A$" & LastRow & ",$A2,$L$2:$L$" & LastRow & ")"
With Range("M2:V" & LastRow)
.FillDown
.Copy
Range("C2").PasteSpecial xlPasteValues
.Clear
End With
For RowNo = LastRow To 2 Step -1
If Range("A" & RowNo) = Range("A" & RowNo - 1) Then
Range("A" & RowNo).EntireRow.Delete
End If
Next
Range("A2").Select
End Sub
Bookmarks