montecarlo2012
Well-known Member
- Joined
- Jan 26, 2011
- Messages
- 986
- Office Version
- 2010
- Platform
- Windows
Hello.
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"),
and the example data
So I am trying to loop this array, but of course do not work, this is my code,
Thank you for reading this.
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"),
VBA 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
and the example data
B | C | D | E | F | G | ODD | EVEN | |
2 | 1 | 2 | 3 | 4 | 5 | 6 | 3 | 3 |
3 | 7 | 8 | 9 | 10 | 11 | 12 | ||
4 | 13 | 14 | 15 | 16 | 17 | 18 | ||
5 | 19 | 20 | 21 | 22 | 23 | 24 | ||
6 | 25 | 26 | 27 | 28 | 29 | 30 | ||
7 | 31 | 32 | 33 | 34 | 35 | 36 | ||
8 | 37 | 38 | 39 | 40 | 41 | 42 | ||
9 | 43 | 44 | 45 | 46 | 47 | 48 |
So I am trying to loop this array, but of course do not work, this is my code,
VBA 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
Last edited by a moderator: