View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
AlanKohl AlanKohl is offline
external usenet poster
 
Posts: 13
Default Specifying a Range in the SUMIFS function

I have 2 pieces of code, the first piece works:
Set rg = Range("Test!G:G")
F = Application.WorksheetFunction.SumIfs(rg, Range("Test!C:C"), "<1")

and the 2nd doesn't work, it fails on the last statement:
With Worksheets("Test")
varCol = 7
Set rg = .Range(.Cells(2, varCol), .Cells(2, varCol).End(xlDown))
End With
F = Application.WorksheetFunction.SumIfs(rg, Range("Test!C:C"), "<1")

What am I doing wrong ? I cannot use the "G:G" syntax because the column I
need to sum is held in a variable (here varCol)

I'm fairly new at Excel programming, so don't hesitate to state the obvious.