Skip to content

Commit eda7ff4

Browse files
authored
Create README.md
0 parents  commit eda7ff4

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# excel_vba_ModulusZero
2+
An alternative to the limited vba Mod() function.
3+
4+
One of the (multiple) probelms with Excel VBA's Mod() function is that it does not support decimals.
5+
Mod() will evaluate a single or double as an integer.
6+
7+
Since I hate microsoft telling me how to do things, I decided to create a way around that failure
8+
with the native Mod() function. That was why I created ModulusZero().
9+
10+
This method does not return the modulus of two numbers, it simply returns TRUE if the modulus is
11+
zero and FALSE if it is anything else. This is particularly handy if you are evaluationg a large
12+
range of numbers against a divisor.
13+
14+
Here is how you would use it:
15+
16+
**In VBA**
17+
18+
Ex 1.
19+
```
20+
If ModulusZero(Range("A1").Value, 0.25) = True Then
21+
22+
... do nifty stuff with Range("A1").Value
23+
24+
end if
25+
```
26+
27+
Ex 2.
28+
```
29+
Dim i as Long
30+
Dim longCount as Long
31+
For i = 1 to 5000
32+
If ModulusZero(Cells(i, 1).Value, 0.125) = True Then
33+
longCount = longCount + 1
34+
End If
35+
Next i
36+
Debug.Print "There were " & longCount & " values that were equally divisible by 0.125"
37+
```
38+
39+
<br><br>
40+
**As A Formula**
41+
You can also use this method as an Excel formula:
42+
43+
<code>=ModulusZero(B12, $A$1)</code>
44+
45+
46+
<br><br>
47+
**To use this method**
48+
49+
You can copy and paste the code into your workbook. You can also download the *.bas file
50+
and import it into your workbook project.
51+
<br><br>
52+
53+
54+

0 commit comments

Comments
 (0)