PDA

View Full Version : Sumif with integer and from another sheet



Borut
06-01-2021, 11:41 AM
In sheet 1 I have one part of te code with sumif. It works fine, if I run from this sheet.
But when I like to run it from another sheet dont work. I didnt found solution.

Part of the of this Code with sumif is (b is interger from 10 to 500):
If Application.WorksheetFunction.SumIf(Range(Cells(b + 4, 2), Cells(b + 36, 2)), Worksheets("Podatki").Range("i22"), Range(Cells(b + 4, 11), Cells(b + 36, 11))) > 0 Then
(this in run fine from sheet 1 and works ok).

but can not write the code, that run from another sheet (something like this):
If Application.WorksheetFunction.SumIf(Worksheets("test").Range(Cells(b + 4, 2), Cells(b + 36, 2)), Worksheets("Podatki").Range("i22"), Worksheets("test").Range(Cells(b + 4, 11), Cells(b + 36, 11))) > 0 Then
solution?
Regards.

SamT
06-01-2021, 04:23 PM
The SumIf is correct. What is after 'Then" (If... Then)

Worksheets("Podatki").Range("i22") must be a string "=32" or ">32") Or

My preference

Dim WSF as Object, evalRng as Range, critRng As Range, sumRng As Range
set WSF = Application.WorksheetFunction

Set evalRng = Worksheets("test").Range("B4:B36").Offset(b)
Set sumRng = Worksheets("test").Range(""K4:K36").Offset(b)
Set critRng = Worksheets("Podatki").Range("i22")

If CBool(WSF.SumIf(evalRng, ">" & critRng.Value, sumRng)) Then
'
'
'