VBA: how to detect an even number?

Solved
mod77 Posted messages 1320 Registration date   Status Member Last intervention   -  
 Nico -
Hello,

I can't display the even numbers in the following loop:

for i =1 to 4

If i = Odd Then 'if i is odd
Cells(12, "A").Value = i

Else 'if i is even
Cells(12, "B").Value = i

End If

next

It shows me all the numbers without going through then but only through Else.

Can you tell me where the error is please?

Thank you.

Configuration: Windows XP 2002 SP3
Excel 2002

Knowing how to say NO is a duty and a strength! Don't be afraid! Unity makes strength!

Mark as resolved if it is!

2 answers

mod77 Posted messages 1320 Registration date   Status Member Last intervention   53
 
I'm answering my question myself because I just found this:

for i = 1 to 4

If i mod 2 <> 0 Then 'if i is odd
Cells(12, "A").Value = i

Else 'if i is even
Cells(12, "B").Value = i

End If

next

--
Knowing how to say NO is a duty and a strength! Don't be afraid! Unity is strength!

Mark as resolved if it is!
25
Nico
 
Thank you
0