Division Me Crazy (Excel) - 2 Ways to Divide Numbers in VBA - Excel Quickie 45

preview_player
Показать описание
There is more than one way to perform division calculations in Excel and it can cause a lot of problems if you don't realize your error...

While the worksheet in Excel allows you to only perform one basic type of division operation, Excel VBA (Macros), allows you to divide using the forward slash "/" and the backslash "\" and they do not work in the same way.

The forward slash performs regular division, the kind that you would expect, this is called floating-point division in this context, and the backslash performs what is called integer division, which has two headache-inducing rules that you must understand if you want to use it or understand why your code is working the way that it is working.

Having two methods for division, and using a similar symbol for the second method, can cause a lot of confusion when making your macros. I hope this quick tutorial can help clear things up for you)

Enjoy this Excel Quickie!

Stay Safe!

#excel #tutorial #excelquickie
Рекомендации по теме
Комментарии
Автор

Great Stuff..This Is One Of The Reasons I Lock My Workbooks-Worksheets To Prevent Colleagues Who Think They Can Code But Always End Up Causing Me Headaches!Thank You Sir :)

darrylmorgan
Автор

great explanation on how vba works, thanks

a-m_Bros_Studios
Автор

Hi.. interesting. According to Microsoft Documentation, the rounding of the dividend (the number to the left) and or the divisor (the number to the right) before the actual division operation is called "banker's rounding" and is used to compensate for bias. The rounding of the quotient (the answer to the division operation) is called truncation. In programming, integer division is distinguished from floating point division which allows for a remainder; integer division does not. In some languages, you get a compile error unless the division is integer based. VBA can handle both, depending on whether you use / (floating point) or \ (integer). Thanks for sharing this information. Before your video, I really knew nothing about it. Nice to have another bit of knowledge added to the tree. Thumbs up!!

wayneedmondson
Автор

Wowwww! Trick unknown for me! Thank you for sharing it.

IvanCortinas_ES
Автор

Awesome,
I tried the back slash and I found out that:
- The number before the backslash rounded up if the decimal part is .5 or more, but
- The number after the backslash (divisor) rounded up if the decimal part is .6 or more

Thanks

makisalimhussain