#### montecarlo2012

##### Well-known Member

- Joined
- Jan 26, 2011

- Messages
- 519

- Office Version
- 2010

- Platform
- Windows

I have a dynamic array B2:G2600 (6 columns), on Col "M" would like to see how many odd numbers there are in the rows, and on Col "N" the even numbers.

So I workout first with the macro recorder, ("this is a short version as example, only"),

Code:

```
Sub CORR_ECT()Range("H2").Select
Selection.FormulaArray = "=COUNT(IF(MOD(A2:F2,2)=0,A2:H2))" ''''EVENS
Range("I2").Select
Selection.FormulaArray = "= COUNT(IF(MOD(A2:F2,2),A2:I2))" '''''ODDS
End Sub
```

Code:

```
[TABLE="width: 792"]
<colgroup><col width="88" span="9" style="width:66pt"> </colgroup><tbody>[TR]
[TD="class: xl65, width: 88"] [/TD]
[TD="class: xl66, width: 88"]B[/TD]
[TD="class: xl66, width: 88"]C[/TD]
[TD="class: xl66, width: 88"]D[/TD]
[TD="class: xl66, width: 88"]E[/TD]
[TD="class: xl66, width: 88"]F[/TD]
[TD="class: xl66, width: 88"]G[/TD]
[TD="class: xl66, width: 88"]ODD[/TD]
[TD="class: xl66, width: 88"]EVEN[/TD]
[/TR]
[TR]
[TD="class: xl65, align: right"]2[/TD]
[TD="class: xl65, align: right"]1[/TD]
[TD="class: xl65, align: right"]2[/TD]
[TD="class: xl65, align: right"]3[/TD]
[TD="class: xl65, align: right"]4[/TD]
[TD="class: xl65, align: right"]5[/TD]
[TD="class: xl65, align: right"]6[/TD]
[TD="class: xl65, align: right"]3[/TD]
[TD="class: xl65, align: right"]3[/TD]
[/TR]
[TR]
[TD="class: xl65, align: right"]3[/TD]
[TD="class: xl65, align: right"]7[/TD]
[TD="class: xl65, align: right"]8[/TD]
[TD="class: xl65, align: right"]9[/TD]
[TD="class: xl65, align: right"]10[/TD]
[TD="class: xl65, align: right"]11[/TD]
[TD="class: xl65, align: right"]12[/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[/TR]
[TR]
[TD="class: xl65, align: right"]4[/TD]
[TD="class: xl65, align: right"]13[/TD]
[TD="class: xl65, align: right"]14[/TD]
[TD="class: xl65, align: right"]15[/TD]
[TD="class: xl65, align: right"]16[/TD]
[TD="class: xl65, align: right"]17[/TD]
[TD="class: xl65, align: right"]18[/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[/TR]
[TR]
[TD="class: xl65, align: right"]5[/TD]
[TD="class: xl65, align: right"]19[/TD]
[TD="class: xl65, align: right"]20[/TD]
[TD="class: xl65, align: right"]21[/TD]
[TD="class: xl65, align: right"]22[/TD]
[TD="class: xl65, align: right"]23[/TD]
[TD="class: xl65, align: right"]24[/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[/TR]
[TR]
[TD="class: xl65, align: right"]6[/TD]
[TD="class: xl65, align: right"]25[/TD]
[TD="class: xl65, align: right"]26[/TD]
[TD="class: xl65, align: right"]27[/TD]
[TD="class: xl65, align: right"]28[/TD]
[TD="class: xl65, align: right"]29[/TD]
[TD="class: xl65, align: right"]30[/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[/TR]
[TR]
[TD="class: xl65, align: right"]7[/TD]
[TD="class: xl65, align: right"]31[/TD]
[TD="class: xl65, align: right"]32[/TD]
[TD="class: xl65, align: right"]33[/TD]
[TD="class: xl65, align: right"]34[/TD]
[TD="class: xl65, align: right"]35[/TD]
[TD="class: xl65, align: right"]36[/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[/TR]
[TR]
[TD="class: xl65, align: right"]8[/TD]
[TD="class: xl65, align: right"]37[/TD]
[TD="class: xl65, align: right"]38[/TD]
[TD="class: xl65, align: right"]39[/TD]
[TD="class: xl65, align: right"]40[/TD]
[TD="class: xl65, align: right"]41[/TD]
[TD="class: xl65, align: right"]42[/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[/TR]
[TR]
[TD="class: xl65, align: right"]9[/TD]
[TD="class: xl65, align: right"]43[/TD]
[TD="class: xl65, align: right"]44[/TD]
[TD="class: xl65, align: right"]45[/TD]
[TD="class: xl65, align: right"]46[/TD]
[TD="class: xl65, align: right"]47[/TD]
[TD="class: xl65, align: right"]48[/TD]
[TD="class: xl65"] [/TD]
[TD="class: xl65"] [/TD]
[/TR]
</tbody>[/TABLE]
```

Code:

```
Sub OD_EV() Dim X As Integer, J As Integer
finalRow = Cells(Row.Count, 2).End(xlUp).Row
For X = 2 To finalRow
For J = 1 To 6
Range("H" & X) = FormulaArray = "=COUNT(IF(MOD(X:J,2)=0,X:J2))" ''''EVENS
Range("I" & X) = FormulaArray = "=COUNT(IF(MOD(X:J,2),X:J2))" 'ODDS
Next J
Next X
End Sub
```