Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Specifying a Range in the SUMIFS function

Sumif takes 2 arrays as the first 2 arguments. Those arrays MUST be the same
size. In your second example your arrays aren't the same size. Make rg the
entire column something like this...

With Worksheets("Test")
varCol = 7
Set rg = .columns(varCol)
End With
F = Application.WorksheetFunction.SumIfs(rg, Range("Test!C:C"), "<1")

--
HTH...

Jim Thomlinson


"AlanKohl" wrote:

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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Specifying a Range in the SUMIFS function

Thanks Jim, that solved the problem.

"Jim Thomlinson" wrote:

Sumif takes 2 arrays as the first 2 arguments. Those arrays MUST be the same
size. In your second example your arrays aren't the same size. Make rg the
entire column something like this...

With Worksheets("Test")
varCol = 7
Set rg = .columns(varCol)
End With
F = Application.WorksheetFunction.SumIfs(rg, Range("Test!C:C"), "<1")

--
HTH...

Jim Thomlinson


"AlanKohl" wrote:

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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SUMIFS using a text range Ziggy Excel Worksheet Functions 2 March 29th 10 01:35 AM
Using SUMIFS with date range Catrina Excel Discussion (Misc queries) 4 January 27th 10 05:10 PM
SUMIFS function lefty Excel Worksheet Functions 4 October 24th 09 04:25 PM
sumifs function bcmlau Excel Discussion (Misc queries) 3 August 4th 09 08:58 AM
Sumifs with error value in the sum range stylissimo Excel Discussion (Misc queries) 10 July 30th 08 05:55 PM


All times are GMT +1. The time now is 03:56 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"