Worksheetfunction.countif for excel 2010

diamantebonita

New Member
Joined
May 25, 2011
Messages
22
<TABLE style="WIDTH: 528pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=705><COLGROUP><COL style="WIDTH: 81pt; mso-width-source: userset; mso-width-alt: 3949" width=108><COL style="WIDTH: 209pt; mso-width-source: userset; mso-width-alt: 10203" width=279><COL style="WIDTH: 143pt; mso-width-source: userset; mso-width-alt: 6985" width=191><COL style="WIDTH: 95pt; mso-width-source: userset; mso-width-alt: 4644" width=127><TBODY><TR style="HEIGHT: 15.75pt" height=21><TD style="BORDER-BOTTOM: windowtext 2pt double; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #fabf8f; WIDTH: 81pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl64 height=21 width=108>DATE ENTERED</TD><TD style="BORDER-BOTTOM: windowtext 2pt double; BORDER-LEFT: windowtext 1pt solid; BACKGROUND-COLOR: #fabf8f; WIDTH: 209pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: windowtext 1pt solid" class=xl74 width=279>VENDOR</TD><TD style="BORDER-BOTTOM: windowtext 2pt double; BORDER-LEFT: windowtext; BACKGROUND-COLOR: #fabf8f; WIDTH: 143pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: windowtext 1pt solid" class=xl66 width=191>AMOUNT</TD><TD style="BORDER-BOTTOM: windowtext 2pt double; BORDER-LEFT: windowtext; BACKGROUND-COLOR: #fabf8f; WIDTH: 95pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: windowtext 1pt solid" class=xl69 width=127>DUE DATE</TD></TR><TR style="HEIGHT: 15.75pt; mso-height-source: userset" height=21><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 15.75pt; BORDER-TOP: windowtext; BORDER-RIGHT: #f0f0f0" class=xl73 height=21>6/10/2011</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: windowtext 1pt solid; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 1pt solid" class=xl75>con edison</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 1pt solid" class=xl67>60.00</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 1pt solid" class=xl70>7/1/2011</TD></TR><TR style="HEIGHT: 15.75pt; mso-height-source: userset" height=21><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl80 height=21> </TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: windowtext 1pt solid; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: windowtext 1pt solid" class=xl79> </TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: windowtext 1pt solid" class=xl68> </TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: windowtext 1pt solid" class=xl71> </TD></TR><TR style="HEIGHT: 18.75pt" height=25><TD style="BORDER-BOTTOM: #fabf8f 1pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 18.75pt; BORDER-TOP: #fabf8f 1pt solid; BORDER-RIGHT: #f0f0f0" class=xl72 height=25>6/22/2011</TD><TD style="BORDER-BOTTOM: #fabf8f 1pt solid; BORDER-LEFT: windowtext 1pt solid; BACKGROUND-COLOR: transparent; BORDER-TOP: #fabf8f 1pt solid; BORDER-RIGHT: windowtext 1pt solid" class=xl76>kleenex</TD><TD style="BORDER-BOTTOM: #fabf8f 1pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: #fabf8f 1pt solid; BORDER-RIGHT: windowtext 1pt solid" class=xl77>87.39</TD><TD style="BORDER-BOTTOM: #fabf8f 1pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: #fabf8f 1pt solid; BORDER-RIGHT: windowtext 1pt solid" class=xl78>6/30/2011</TD></TR><TR style="HEIGHT: 18.75pt" height=25><TD style="BORDER-BOTTOM: #fabf8f 1pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 18.75pt; BORDER-TOP: #fabf8f; BORDER-RIGHT: #f0f0f0" class=xl72 height=25>6/22/2011</TD><TD style="BORDER-BOTTOM: #fabf8f 1pt solid; BORDER-LEFT: windowtext 1pt solid; BACKGROUND-COLOR: transparent; BORDER-TOP: #fabf8f; BORDER-RIGHT: windowtext 1pt solid" class=xl76>staples</TD><TD style="BORDER-BOTTOM: #fabf8f 1pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: #fabf8f; BORDER-RIGHT: windowtext 1pt solid" class=xl77>99.00</TD><TD style="BORDER-BOTTOM: #fabf8f 1pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: #fabf8f; BORDER-RIGHT: windowtext 1pt solid" class=xl78>6/30/2011</TD></TR><TR style="HEIGHT: 18.75pt" height=25><TD style="BORDER-BOTTOM: #fabf8f 1pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 18.75pt; BORDER-TOP: #fabf8f; BORDER-RIGHT: #f0f0f0" class=xl72 height=25> </TD><TD style="BORDER-BOTTOM: #fabf8f 1pt solid; BORDER-LEFT: windowtext 1pt solid; BACKGROUND-COLOR: transparent; BORDER-TOP: #fabf8f; BORDER-RIGHT: windowtext 1pt solid" class=xl76> </TD><TD style="BORDER-BOTTOM: #fabf8f 1pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: #fabf8f; BORDER-RIGHT: windowtext 1pt solid" class=xl77> </TD><TD style="BORDER-BOTTOM: #fabf8f 1pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: #fabf8f; BORDER-RIGHT: windowtext 1pt solid" class=xl78> </TD></TR><TR style="HEIGHT: 18.75pt" height=25><TD style="BORDER-BOTTOM: #fabf8f 1pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 18.75pt; BORDER-TOP: #fabf8f; BORDER-RIGHT: #f0f0f0" class=xl72 height=25>6/21/2011</TD><TD style="BORDER-BOTTOM: #fabf8f 1pt solid; BORDER-LEFT: windowtext 1pt solid; BACKGROUND-COLOR: transparent; BORDER-TOP: #fabf8f; BORDER-RIGHT: windowtext 1pt solid" class=xl76>texas instruments</TD><TD style="BORDER-BOTTOM: #fabf8f 1pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: #fabf8f; BORDER-RIGHT: windowtext 1pt solid" class=xl77>56.00</TD><TD style="BORDER-BOTTOM: #fabf8f 1pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: #fabf8f; BORDER-RIGHT: windowtext 1pt solid" class=xl78>6/29/2011</TD></TR></TBODY></TABLE>

the above is just a sample of a much longer list. But the list itself is broken up into several named ranges. Within each range i want to count the number of entries where the date is today or a week from today (date + 7). I'm doing this in VBA so I'm using worksheetfunction.countif(). But I cant seem to get the parameters right.
When i type:

worksheetfunction.countif(llci,">=date + 7")

the error says "Compile error, expected: ="
Can someone tell me what im doing wrong?

llci is just the name of my first range.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
try (untested):
worksheetfunction.countif(llci,">=" & date + 7)

although date + 7 will count how many there are AFTER a week from today - but that's may what you want to do (to subtract it from >=today's date).
 
Upvote 0
Maybe


Application.CountIf(Range("llci"), ">=" & Format(Date + 7, "mm/dd/yyyy"))


(i'm using Format because of possible wrong results depending on dates regional settings)


HTH


M.
 
Upvote 0
this section copies certain cells to another part of the spreadsheet, making a list
For Each icell In ws1.Range("G2:G" & lastrow)
If icell.Value >= Date + 7 And icell.Value < Date + 14 Then
Range(icell.Offset(0, -2), icell).Copy Destination:=ws1.Range("AA" & Rows.Count).End(xlUp).Offset(1, 0)
End If
Next icell

Range("AA2").Select

listrow = ws1.Range("AC" & Rows.Count).End(xlUp).Row

counti = worksheetfunction.countif(llci, ">=date = 7)

this section will use the count to skip down a number of rows, insert a row and add text (not quite finished with this section)
If counti > 0 Then
Rows("1:1").EntireRow.Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
 
Upvote 0
So i was thinking of ditching countif as a solution and doing this instead:

For Each g In ws1.Range(llci)
If g.Value >= Date + 7 And g.Value < Date + 14 Then
counti = counti + 1
End If
Next g

what you think?
 
Upvote 0
this section copies certain cells to another part of the spreadsheet, making a list
For Each icell In ws1.Range("G2:G" & lastrow)
If icell.Value >= Date + 7 And icell.Value < Date + 14 Then
Range(icell.Offset(0, -2), icell).Copy Destination:=ws1.Range("AA" & Rows.Count).End(xlUp).Offset(1, 0)
End If
Next icell

Range("AA2").Select

listrow = ws1.Range("AC" & Rows.Count).End(xlUp).Row

counti = worksheetfunction.countif(llci, ">=date = 7)

this section will use the count to skip down a number of rows, insert a row and add text (not quite finished with this section)
If counti > 0 Then
Rows("1:1").EntireRow.Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
This line from above,
counti = worksheetfunction.countif(llci, ">=date = 7)
isn't the same as any suggestions put forward so yes, it will give a syntax error.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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