Worksheetfunction.Countifs question

Pyrgos

New Member
Joined
Feb 22, 2012
Messages
30
Hello there,

I have been trying to make the below code work, but I can't seem to make it work

Code:
With shCAP
                        Dim Result As Integer, b As Long, theDate as Date
                        Dim rngAssociates As Range, rngDates As Range, Associate as Range
                        b = lastRow(shCAP) 'retrieves last row of the sheet
                        Set Associate = shMain.Range("B" & Selection.Row)                        
                        Set rngAssociates = .Range("A2:A" & b)
                        Set rngDates = .Range("C2:C" & b)
                        theDate = shMain.Range("C" & Associate.Row)
                        Result = WorksheetFunction.CountIfs(rngAssociates, Associate, _
                          rngDates, ">=" & theDate, rngDates, "<=" & DateAdd("m", 1, theDate) - 1)
                          Debug.Print Result & " " & Associate & " " & theDate & " "; DateAdd("m", 1, theDate) - 1
                    End With

I have tried Associate.Value. I have tried CDate() on the date ranges. No success.

My debug.print code returns Result as always 0, even though I am sure the columns and sheet are correct, and that there are instances where the count would be more than zero.

Is there anything wrong in my syntax?
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I haven't tried it but you could try casting the dates, and is there an extra ASsociate?

Code:
cWorksheetFunction.CountIfs(rngAssociates, _
                          rngDates, ">=" & CLng(theDate), rngDates, "<=" & CLng(DateAdd("m", 1, theDate) - 1))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,334
Members
452,636
Latest member
laura12345

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