Using VBA how do i do a COUNTIFS

ScotlandsNeo

New Member
Joined
Nov 12, 2015
Messages
10
Hi all,

I am trying to use application.worksheetfunction.countifs in order to do a quick countifs across 4 columns where the follwing criteria is met.
Column 1 (ref_Col) has values lower than £50
columns 2,3 and 4 have no entries and are blank cells.
If the above condition is not met then do not count.

so far i have the following code

LR is just my variable for last row where it counts up from lastrow '.end(xlup).row'
v1 is variable that is taking the value from a ccell, in this case '50'
val1 is the variable i want to set that gives me my countifs result and i can then use that to paste into my sheet directly.

Code:
val1 = application.worksheetfunctions.countifs(Range(Sheets(1).cells(1, ref_col), sheets(1).cells (LR, Ref_Col)), "<" & v1)

this code counts correctly that my column 'REF_COL' has 3 values less than £50. How do i extend this so that it also checks columns 2,3 and 4 have no entries adjacent to the values, and if they do then not to count it.
 
Last edited:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Add more criteria to your COUNTIFS?

Code:
worksheetfunctions.countifs(Range(Sheets(1).cells(1, ref_col), sheets(1).cells (LR, Ref_Col)), "<" & v1, range2, criteria2, range3, criteria3, etc....)
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,988
Members
448,538
Latest member
alex78

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