MOD Function

B

Bernard Jason

My previous posting went out with "Microsoft "as the sender, this is an
error on my part as I had not completely set up my news account. My
apologies to MS

_____________________________________________________________________

I am unable to use the MOD Function within a module. The line gets
highlighted in red and does not offer any comments or hint as to why.

However if I use the function within the spreadsheet I get the desired
results.
I looked at the reference section for any unusual entries but found nothing.

I am using office 2003. There is no problem with the syntax

Many thanks
Bernard
 
A

Alan Beban

Bernard said:
My previous posting went out with "Microsoft "as the sender, this is an
error on my part as I had not completely set up my news account. My
apologies to MS

_____________________________________________________________________

I am unable to use the MOD Function within a module. The line gets
highlighted in red and does not offer any comments or hint as to why.

However if I use the function within the spreadsheet I get the desired
results.
I looked at the reference section for any unusual entries but found nothing.

I am using office 2003. There is no problem with the syntax

Many thanks
Bernard
It's usually helpful if you post the relevant code. Without it we're
guessing. The problem is probably that you are using the spreadsheet
syntax, Mod(6,4), rather than the VBA syntax, 6 Mod 4

Alan Beban
 
B

Bernard Jason

Thanks for your reply, Alan,
I'm using the spreadsheet syntax ie Var1=Mod(something,4) within a function
I am creating to check leap years.
If this is not appropriate, I welcome suggestions.
Many thanks
Bernard
 
R

Ron Rosenfeld

My previous posting went out with "Microsoft "as the sender, this is an
error on my part as I had not completely set up my news account. My
apologies to MS

_____________________________________________________________________

I am unable to use the MOD Function within a module. The line gets
highlighted in red and does not offer any comments or hint as to why.

However if I use the function within the spreadsheet I get the desired
results.
I looked at the reference section for any unusual entries but found nothing.

I am using office 2003. There is no problem with the syntax

Many thanks
Bernard

Post the code you are using.
--ron
 
D

Dave Peterson

Take a look at VBA's help (not Excel's help for Mod):

Option Explicit
Sub testme()
Dim a As Double
a = 19 Mod 3
MsgBox a
End Sub
 
A

Alan Beban

As I guessed in my reply, you are using worksheet syntax instead of VBA
syntax. Switch to

Var1 = something Mod 4

Alan Beban
 
B

Bernard Jason

Dear Alan & Dave,

Thanks so much, with your suggestions and help I have overcome my problem.
It appears to me that the current VB versions are most unforgiving because I
remember clearly having used the spreadsheet syntax in the past.

Thanks again.
Bernard
 
D

Dana DeLouis

This probably won't matter, but just be aware that the use of Mod for leap
years will work for the year 2100. This would return True, but the year
2100 does not have a leap year.

Dim LeapYear As Boolean
LeapYear = (2100 Mod 4) = 0

Two popular techniques are:

LeapYear = Day(DateSerial(2100, 2, 29)) = 29
LeapYear = Day(DateSerial(2100, 3, 0)) = 29


For me, using Mod(2000,4) in vba highlights the line in Red, and returns a
message: "Compile error: Expected: expression"

HTH
Dana DeLouis
 
E

Earl Kiosterud

Bernard,

The difference is between functions and operators. Both worksheet formulas
and VBA have many functions and operators. Worksheets formulas have a mod
function,
mod(Something, 4), but no mod operator. VBA has no mod function, but has a
mod operator, Something mod 4.
 

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

Function MOD 6
Excel Repeating a RAND() function under certain conditions 0
Mod Function 4
SUMIF using value from MOD function 2
MOD function not returning exact zero 2
Using Now() in a Function 2
Mod 2
MOD function results 2

Top