View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave D-C[_3_] Dave D-C[_3_] is offline
external usenet poster
 
Posts: 176
Default Adding certain cells

Maybe it's my XL97, but I didn't get this to work.
Here's a variation using your idea:
Sub sub1()
Dim iRow&, s$
Range("d1") = "Header?"
Range("a1:b5").Copy Range("d2:e6")
Range("d1:d6").AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Range("f1"), Unique:=True
iRow = 2
Do Until Cells(iRow, 6) = ""
s = "=SumIf(d2:d6, " & Cells(iRow, 6).Address & ",e2:e6)"
Cells(iRow, 7) = s
MsgBox Cells(iRow, 6) & ": " & Cells(iRow, 7)
iRow = iRow + 1
Loop
End Sub

Chip wrote:
Here is a start:
Range("A1:A6").AdvancedFilter Action:=xlFilterCopy,
CopyToRange:=Range("E1"), Unique:=True
Range("F2").Select
ActiveCell.FormulaR1C1 =
"=SUMIF(RC[-5]:R[4]C[-5],RC[-1],RC[-4]:R[4]C[-4])"
Range("F2").Select
Range("F2").Select
Selection.End(xlDown).Select
lastrow = ActiveCell.Row + 1
Range("F2").Select
Do Until ActiveCell.Row = lastrow
MsgBox ("Total: " & ActiveCell.Value)
ActiveCell.Offset(1, 0).Select
Loop


JN wrote:
I have two ranges, A1:A5, B1:B5.
I want to have a macro that looks up all the values in the 1st range
and add all the cells in 2nd range that match in the 1st range
and have a msgbox output the totals.
For Example:
A B
10 1
5 2
15 3
10 4
15 5
Output:
10 5
5 2
15 8