-1

I want to use the countif statement to calculate the number of employee (in my example) whose gender are Male and their age is between 15 to 30. I am not sure how to add another argument to the countif statement to add the restriction of gender, since it just take 2 statements. Here is my function code:

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

This is the code that I want to add as the 3rd argument to the countif statement.

(Cells(i, Column_of_reference ) = level_of_reference ) ' this shows that Gender is male (or female) when level_of_reference is 1 (or 2).

Zapata
  • 133
  • 1
  • 5
  • 20

1 Answers1

2

You have to resort to Countifs, with any number of conditions.

Plus, you can consolidate the two numeric conditions into one (abs((x-(xmin+xmax)/2) < (xmax-xmin)/2).