Count cells that contain even numbers
Macro Title:
|
Worksheet Variable:
|
Data Variable:
|
Cell Variable:
|
Result Variable:
|
Worksheet Name:
|
Range Reference:
enter the range from which you want to count the number of cells that contain even numbers |
Output Cell:
|
First Comment:
' |
Second Comment:
' |
Sub Count_cells_that_contain_even_numbers()
'declare variables
Dim ws As Worksheet
Dim DataRng As Range
Set ws = Worksheets("Analysis")
Set DataRng = ws.Range("B5:B9")
Set DataRng = ws.Range("B5:B9")
evennum = 0
'count cells that contain even numbers by looping through each cell in range (B5:B9)
For Each xcell In DataRng
If xcell Mod 2 = 0 Then
evennum = evennum + 1
End If
Next xcell
ws.Range("D5") = evennum
End Sub
Sub Count_cells_that_contain_even_numbers()
'declare variables
Dim ws As Worksheet
Dim DataRng As Range
Dim ws As Worksheet
Dim DataRng As Range
Set ws = Worksheets("Analysis")
Set DataRng = ws.Range("B5:B9")
Set DataRng = ws.Range("B5:B9")
evennum = 0
'count cells that contain even numbers by looping through each cell in range (B5:B9)
For Each xcell In DataRng
For Each xcell In DataRng
If xcell Mod 2 = 0 Then
evennum = evennum + 1
End If
Next xcell
ws.Range("D5") = evennum
End Sub