How To Use MOD In VBA - Excel Champs
Có thể bạn quan tâm
In VBA, MOD is an operator, not a function and this operator helps you to divide two numbers and returns the remainder value in the result.
It’s equivalent to the mod function in Excel.
You can use the mod in so many ways and, in this tutorial, we will see some examples. Use the below steps to use the mod operator in VBA:
Range("A1") = 10 Mod 3- Specify the first number which you want to get divided.
- After that, enter the “mod” operator.
- Now, enter a number that you want to divide by.
- In the end, use a message box or a cell to get the remainder from the division.
In the same way, you can also get the remainder using a message box.
And in the following code, we used a message box and then used the mod operator to get the remainder after dividing.
MsgBox 9 Mod 3And when you run this code, it returns zero in the result in the message box as when you divide 9 by 3 there’s no remainder left, so as in the result of this code.
Note: As I said, there’s also a function in Excel to get the remainder from the division of two numbers and there are a few situations where you will find that the result you get from Excel will be different from the result you got in VBA.
Error in MOD
If you try to divide a number with zero it always returns a division by zero error.
Debug.Print 10 Mod 0And the above code returns that error.
What is VBARelated Tutorials
- Average Values in Excel using VBA
- Get Today’s Date and Current Time using VBA
- Sum Values in Excel using VBA
- Match Function in VBA
- VBA Random Numbers
- VBA Calculate
- VBA Concatenate
- VBA Worksheet Function
Từ khóa » Visual Basic Mod Operator
-
Mod Operator - Visual Basic | Microsoft Docs
-
Mod Operator - Microsoft Docs
-
Can Someone Explain The 'mod' Operator In In The Simplest ...
-
VB.NET Mod: Modulo Division Example - Dot Net Perls
-
Mod Operator - Microsoft Visual Basic Constants Documentation
-
Mod Operator In Excel VBA (In Easy Steps)
-
Mod - Operator Of Language VBScript - Promotic
-
How To Use VBA Mod Operator (9 Examples) - ExcelDemy
-
Mod Operator - ADM Help Centers
-
Mod Operator - VB .NET Language In A Nutshell [Book]
-
MS Excel: How To Use The MOD Function (VBA) - TechOnTheNet
-
Viacheslav Eremin | Visual Basic Language Reference | Mod Operator