RiMa
RiMa

Reputation: 85

If statement to choose a value

Hi I have the following code:

If Numcolyo = Even Then
    .StartPoint.y = BuWidth / 2 + ccFacoy
    Else
    .StartPoint.y = BuWidth / 2
    End If

But it doesn't do what I expect it to do. The code works though. Say for example if Numcolyo=4 then I want the first statement to be true: StartPoint.y = BuWidth / 2 + ccFacoy

If Numcolyo=3 then I want the second statement to be true: StartPoint.y = BuWidth / 2

Have I written anything wrong? Thankful for any kind of help :)

Upvotes: 0

Views: 66

Answers (1)

VBlades
VBlades

Reputation: 2251

Don't think there is an EVEN keyword in VBA. Try it with the modulus operator which returns the remainder of a division operation:

If Numcolyo Mod 2 = 0  Then
    .StartPoint.y = BuWidth / 2 + ccFacoy
Else
    .StartPoint.y = BuWidth / 2
End If

When something divided by 2 has no remainder, it is even.

Upvotes: 5

Related Questions