Consulting

Results 1 to 2 of 2

Thread: Sumif with integer and from another sheet

  1. #1
    VBAX Regular
    Joined
    Oct 2020
    Posts
    24
    Location

    Sumif with integer and from another sheet

    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.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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
    '
    '
    '
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •