MOD Function

  • Thread starter Thread starter Bernard Jason
  • Start date Start date
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
 
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
 
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
 
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
 
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
 
As I guessed in my reply, you are using worksheet syntax instead of VBA
syntax. Switch to

Var1 = something Mod 4

Alan Beban
 
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
 
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
 
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.
 
Back
Top