I have a set of data that I ran Excel's embedded Subtotals function in the Data tab and used the Sum function in column "I" for each change in column "B". I am wanting to do a weighted average of column "L" based on column "I". I found this set of code in the forum that should take of this:
Sub test()
For Each c In Intersect(ActiveSheet.UsedRange, ActiveSheet.Range("I:I"))
If Left(c.FormulaR1C1, 4) = "=SUB" Then
c.Offset(0, 3).Formula = "=(SUMPRODUCT(" & c.Precedents.Address & "*" & c.Precedents.Offset(0, 3).Address & ")/SUM(" & c.Precedents.Address & "))"
End If
Next
End Sub
Unfortunately instead of returning =SUMPRODUCT(I:I*L:L)/SUM(I:I) it is returning =SUMPRODUCT(I:I,A:A*L:L,D:D)/SUM(I:I,D:D). Does anyone know why it is doing this? Thanks ahead of time!
Sub test()
For Each c In Intersect(ActiveSheet.UsedRange, ActiveSheet.Range("I:I"))
If Left(c.FormulaR1C1, 4) = "=SUB" Then
c.Offset(0, 3).Formula = "=(SUMPRODUCT(" & c.Precedents.Address & "*" & c.Precedents.Offset(0, 3).Address & ")/SUM(" & c.Precedents.Address & "))"
End If
Next
End Sub
Unfortunately instead of returning =SUMPRODUCT(I:I*L:L)/SUM(I:I) it is returning =SUMPRODUCT(I:I,A:A*L:L,D:D)/SUM(I:I,D:D). Does anyone know why it is doing this? Thanks ahead of time!