我想使用countif语句来计算其性别为男性且年龄在15到30之间的员工人数(在我的示例中)。我不知道如何在countif语句中添加另一个参数来添加限制性别,因为它只需要2个陈述。 这是我的功能代码:
Function Calculate(Column_target As Integer, Row_number As Double, Level_of_response As Integer, Column_of_reference As Integer, level_of_reference As Integer) As Double
Sheets("A").Select
Range(Cells(2, Column_target ), Cells(Row_number , Column_target )).Select
For i = 3 To Row_number + 1
If (Level_of_response = 1) Then
Calculate = (Application.WorksheetFunction.CountIf(Selection, "<31") - Application.WorksheetFunction.CountIf(Selection, "<15")) / (Row_number - 1)
End If
这是我想要添加为countif语句的第3个参数的代码。
(Cells(i, Column_of_reference ) = level_of_reference )
'这表明当level_of_reference为1(或2)时,性别是男性(或女性)。
答案 0 :(得分:2)
您必须诉诸Countifs
,并且有许多条件。
另外,您可以将两个数值条件合并为一个(abs((x-(xmin + xmax)/ 2)&lt;(xmax-xmin)/ 2)。