Count cells that contain even numbers
Macro Title:
|
Worksheet Variable:
|
Result Variable:
|
Row Reference Variable:
|
Worksheet Name:
|
Column Reference:
enter the column reference from which you want to count the number of cells that contain even numbers |
First Row Reference:
enter the first row reference which represents the first row of the range from which you want to count the number of cells that contain only even numbers |
Last Row Reference:
enter the last row reference which represents the last row of the range from which you want to count the number of cells that contain only even numbers |
Output Cell:
|
First Comment:
' |
Second Comment:
' |
Sub Count_cells_that_contain_even_numbers()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
evennum = 0
'count cells that contain even numbers by looping through rows 5 to 9 in column B
For x = 5 To 9
If ws.Range("B" & x) Mod 2 = 0 Then
evennum = evennum + 1
End If
Next x
ws.Range("D5") = evennum
End Sub
Sub Count_cells_that_contain_even_numbers()
'declare a variable
Dim ws As Worksheet
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
evennum = 0
'count cells that contain even numbers by looping through rows 5 to 9 in column B
For x = 5 To 9
For x = 5 To 9
If ws.Range("B" & x) Mod 2 = 0 Then
evennum = evennum + 1
End If
Next x
ws.Range("D5") = evennum
End Sub