Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional COUNTIF using logicals

Status
Not open for further replies.

AJ2002

Electrical
Mar 4, 2002
27
I have an array of 8760 hourly data kW readings for a year (24 by 365). I want to count the number of hours >= 15000 this works but then using and the AND logical it does not work. Here is formula that does not work =countif(D4:AA368), (AND>14900, (D4:AA368)<=15000)) it gives me zero.

Can someone please help me out with this feature?
 
Replies continue below

Recommended for you

Won't the AND function have a problem with the a range comparision? Could you add an additional column that puts a 1 or 0 in next to the cell, and just reference 2 different cells to create your limit criteria? For example:

Assume D1 contains the minimum value (14900), and D2 contains the max value (15000).

=if(AND(D4>$D$1,D4<=$D$2),1,0)

Then just copy the formula, and sum the results?
 
CountIf doesn't seem to like logical operators in its Criteria argument.

You could always use a Macro:
[tt]
Sub Macro1()
Dim c As Range
Dim x As Range
Set x = Sheet1.Range("D4:AA368")
For Each c In x
If c.Value <= 15000 And c.Value > 14900 Then
q = q + 1
End If
Next c
Sheet1.Range("a1").Value = q
End Sub
[/tt]

Good Luck
johnwm
________________________________________________________
To get the best from these forums read faq731-376 before posting
 
Use the following as an array formula.

SUM(IF(C3:C8762>15000,1,0))

Array function? Use <crtl>-<shift>-<enter> rather than just <enter> when you have finished typing the formula. The formula will then appear as if you typed it with {braces} around it.

For greater flexibility, you can put your threshold value of 15000 into a cell and reference that cell in the IF function.

HTH
 
Why not COUNTIF(D4:AA368,">=15000")? If you want to make the criteria general, say entering 15000 in cell A1, then use COUNTIF(D4:AA368,">="&TEXT(A1,"##")). This isn't an array formula and you don't need to use Ctrl-shft-enter.

 
or COUNTIF(D4:AA368,">14900")-COUNTIF(D4:AA368,">15000")

TTFN
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor