Thread: Sumif Macro
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Christopher Panadol Christopher Panadol is offline
external usenet poster
 
Posts: 6
Default Sumif Macro (Revised)

Option Explicit
Sub Main()

Dim xRow, yRow, xClause

xRow = 2
Do While Not IsEmpty(Cells(xRow,1).Value) ' Assume each cell of your
column 1 is not empty
xRow = xRow + 1
Loop

yRow = xRow + 2 ' Shift two rows to enter your formula
Cells(yRow, 8).FormulaR1C1 = "=SUMIF(R[-" & Trim(Str(xRow)) & _
"]C[-2]:R[-3]C[-2], 40, R[-" & Trim(Str(xRow)) & "]C:R[-3]C)"

Cells(yRow + 1, 8).FormulaR1C1 = "=SUMIF(R[-" & Trim(Str(xRow + 1)) & _
"]C[-2]:R[-4]C[-2], 40, R[-" & Trim(Str(xRow + 1)) & "]C:R[-4]C)"

End Sub