Use Mod?

dinotom

Active Member
Joined
Aug 2, 2009
Messages
357
I am trying to test to see if a certain number is a multiple of 25 , ie its 25,50,75,100 etc etc

something like;
If myNumber is a multiple of 25 then
Else
rest of code
End if
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
there is no VBA MOD operator, so you will have to use something like:
Code:
If WorksheetFunction.MOD(MyNum, 25) = 0 then
   do stuff
End If
...
 
Upvote 0
Code:
if myNumber mod 25 = 0 then
 
Upvote 0
Hi Thomas

Just a remark: be careful when using Mod. The Mod() worksheet function and the Mod vba operator have the same name but do not always behave in the same way. Be sure to check the help before using them.
 
Last edited:
Upvote 0
For testing for zero it doesn't matter, but the MOD function always returns a non-negative number, while the Mod operator returns the smaller of the positive and negative modulus, and Mod rounds its arguments to Long.
 
Last edited:
Upvote 0
while the Mod operator returns the smaller of the positive and negative modulus
That's not exactly correct ... maybe I can fix it.
 
Upvote 0
Yes, I was just reminding that they are false friends, they look the same but they are not the same.

That's not a problem here, anyway, there's no Mod() method in the WorksheetFunction object (or, at least there didn't use to be, can't check here in recent versions of Excel). If one wanted to use the Mod() worksheet function in vba, one would have to, for ex., use Evaluate().
 
Upvote 0
The num1 Mod num2 returns a number with the same sign as num1.
 
Upvote 0

Forum statistics

Threads
1,224,559
Messages
6,179,517
Members
452,921
Latest member
BBQKING

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top