Trouble using WorksheetFunction SUM and COUNTIFS together
I’m trying to write a small vba where I need to check two conditions and if they the conditions are met add total the number of records that meet the conditions. My code is as follows:
wsActive.Range(“D2”).Value = Application.WorksheetFunction.SUM(WorksheetFunction.COUNTIFS(Range(“K:K”), “>12”, Range(“I:I”), {“”Open””,””Under Investigation””,””Acknowledge & Close””}))
wsTables.Range(“D3”).Value = Application.WorksheetFunction.SUM(Application.WorksheetFunction.CountIfs(Range(“K:K”), “>=6”, Range(“K:K”), “<=12”, Range(“I:I”), {“”Open””,””Under Investigation””,””Acknowledge & Close””}))
When I run the code, I get a message stating the braces, “{“, are invalid characters.
When I remove the braces, then I get a message missing an object.
Can someone tell me what I am doing wrong? I know I can use the functions in the cell, but I need it to be in a macro. When I apply the function to the cell, it works; however, when I try to write it in Excel VBA, it fails.
I’m trying to write a small vba where I need to check two conditions and if they the conditions are met add total the number of records that meet the conditions. My code is as follows: wsActive.Range(“D2”).Value = Application.WorksheetFunction.SUM(WorksheetFunction.COUNTIFS(Range(“K:K”), “>12”, Range(“I:I”), {“”Open””,””Under Investigation””,””Acknowledge & Close””})) wsTables.Range(“D3”).Value = Application.WorksheetFunction.SUM(Application.WorksheetFunction.CountIfs(Range(“K:K”), “>=6”, Range(“K:K”), “<=12”, Range(“I:I”), {“”Open””,””Under Investigation””,””Acknowledge & Close””})) When I run the code, I get a message stating the braces, “{“, are invalid characters.When I remove the braces, then I get a message missing an object. Can someone tell me what I am doing wrong? I know I can use the functions in the cell, but I need it to be in a macro. When I apply the function to the cell, it works; however, when I try to write it in Excel VBA, it fails. Read More