MOD function

  • Thread starter Thread starter Srikanth Ganesan
  • Start date Start date
S

Srikanth Ganesan

Hello,

How do I do the following in a macro

IF MOD(n,2) = 1 Then posX = -190 Else posX = 150


where n is an integer, posX is a Long.

Srikanth
 
Hi Srikanth

Sub test()
Dim N As Long
Dim posX As Long
For N = 1 To 6
posX = 150 - (N Mod 2) * 340
MsgBox N & Chr(10) & posX, , "demo"
Next
End Sub


HTH. Best wishes Harald
 
Srikanth,

There is no MOD function in VBA, but there is a Mod operator. So you would
write:

IF n Mod 2 = 1 then
PosX = -190 ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top