0
How to find odd and odd pairs from this list?
Sub kati()
For li = 1 To 10
For col = 1 To 10
0
How to find odd and odd pairs from this list?
Sub kati()
For li = 1 To 10
For col = 1 To 10
8
Use the mod operator. If the rest of the division by 2 is 0, then the number is even. Example:
If li Mod 2 = 0 then 'faça o que quiser aqui
If col Mod 2 = 0 then 'faça o que quiser aqui
2
Idem to the operator Mod, can be done like this (whereas it is a matrix):
If Matriz(li, col) / 2 - Int(Matriz(li, col) / 2) = 0 Then MsgBox Matriz(li, col) & " é Par" Else MsgBox Matriz(li, col) & " é Impar"
Very good Leo, I liked it very much, I only had a doubt, I could explain the mathematical operation?
Of course, when dividing an integer by 2, if there is no rest it is even, if there is rest it is odd. The equation takes the result of the division by 2 and subtracts from the whole part of this same result, if 0 is that there was no rest, then the number is even; if 0.5 is that it had rest, then the number is odd. For example: 18/2 - INT(18/2) = 9 - 9 = 0 (Even), 23/2 - INT(23/2) = 11,5 - 11 = 0,5 (Odd), that’s it.
Browser other questions tagged vba mathematics operators
You are not signed in. Login or sign up in order to post.
And where’s the list?
– Bacco
Did any of the answers below solve your problem? Do you think you can accept one of them? Check out the [tour] how to do this, if you still don’t know how to do it. This helps the community by identifying the best solution for you. You can only accept one of them, but you can vote for any question or answer you find useful on the entire site.
– Maniero