And OR in WorksheetFunction.CountIf and SumIfs

jameslio

New Member
Joined
Feb 6, 2018
Messages
3
Hi there

I have an excel sheet that I need to count value <5 and >0

Sheets("READ_ME").Cells(40, 2) = WorksheetFunction.CountIf(Sheets("JOIN_DATA").Range("i:i"), "<5"

and to sum if <5 and >0

Sheets("READ_ME").Cells(41, 2) = WorksheetFunction.SumIfs(Sheets("JOIN_DATA").Range("g:g"), Sheets("JOIN_DATA").Range("i:i"), "<5")

How do I use AND function in this?

Thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Same as worksheetfunction.
Code:
Sheets("READ_ME").Cells(40, 2) = WorksheetFunction.CountIf(Sheets("JOIN_DATA").Range("i:i"), "<5",Sheets("JOIN_DATA").Range("i:i"),">0")

Sheets("READ_ME").Cells(41, 2) = WorksheetFunction.SumIfs(Sheets("JOIN_DATA").Range("g:g"), Sheets("JOIN_DATA").Range("i:i"), "<5",Sheets("JOIN_DATA").Range("i:i"), ">0")

Tidy
Code:
With Sheets("JOIN_DATA")
    Sheets("READ_ME").cells(40, 2) = WorksheetFunction.CountIf(.Range("i:i"), "<5", .Range("i:i"), ">0")
    Sheets("READ_ME").cells(41, 2) = WorksheetFunction.SumIfs(.Range("g:g"), .Range("i:i"), "<5", .Range("i:i"), ">0")
End With
 
Upvote 0
Thanks but your code does not work it said Compile Error Wrong number of arguments or invalid property assignment


Same as worksheetfunction.
Code:
Sheets("READ_ME").Cells(40, 2) = WorksheetFunction.CountIf(Sheets("JOIN_DATA").Range("i:i"), "<5",Sheets("JOIN_DATA").Range("i:i"),">0")

Sheets("READ_ME").Cells(41, 2) = WorksheetFunction.SumIfs(Sheets("JOIN_DATA").Range("g:g"), Sheets("JOIN_DATA").Range("i:i"), "<5",Sheets("JOIN_DATA").Range("i:i"), ">0")

Tidy
Code:
With Sheets("JOIN_DATA")
    Sheets("READ_ME").cells(40, 2) = WorksheetFunction.CountIf(.Range("i:i"), "<5", .Range("i:i"), ">0")
    Sheets("READ_ME").cells(41, 2) = WorksheetFunction.SumIfs(.Range("g:g"), .Range("i:i"), "<5", .Range("i:i"), ">0")
End With
 
Upvote 0
Hi all thanks nevermind got it to work I have to put "s" at the back of CountIfs. Jesus can VBA be that bad in programming? Prefer C
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top