Count cells that contain odd numbers
Macro Title:
|
Worksheet Variable:
|
Data Variable:
|
Cell Variable:
|
Formula Variable:
|
Result Variable:
|
Worksheet Name:
|
Range Reference:
enter the range from which you want to count the number of cells that contain odd numbers |
Output Cell:
|
First Comment:
' |
Second Comment:
' |
Sub Count_cells_that_contain_odd_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")
'count cells that contain odd numbers by looping through each cell in range (B5:B9)
For Each xcell In DataRng
cellmod = xcell Mod 2
oddnum = oddnum + cellmod
Next xcell
ws.Range("D5") = oddnum
End Sub
Sub Count_cells_that_contain_odd_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")
'count cells that contain odd numbers by looping through each cell in range (B5:B9)
For Each xcell In DataRng
For Each xcell In DataRng
cellmod = xcell Mod 2
oddnum = oddnum + cellmod
Next xcell
ws.Range("D5") = oddnum
End Sub