MOD function

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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
H

Harald Staff

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
 
E

Earl Kiosterud

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

Similar Threads

Functions in Excel macro 2
max/min of a selected range of cells 1
Cell Address help 1
Chart size/position 1
Last Cell 3
Data Form 1
Summing N/A's 5
usage "AddressOf TimerProc" in Excel97 1

Top