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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
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,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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