Macro for automatic division of values in cells by an arbitrary number. It may be necessary if we have a data file where all values are specified in pennies, and we need to translate calculations and data into hryvnias (or another currency).
Of course, you can use formulas to convert values, but if there are a lot of numbers, then converting in this way will be very long and boring.
Let's consider how to divide all selected cells by a number, for example,
To do this, open your book, go to Visual Basic Editor (Alt+F11), add module VBA ( Insert - Module ) and copy this macro text there:
Sub Division() For Each cell In Selection cell.Formula = cell.Value Next cell For Each cell In Selection cell.Value = cell.Value / 100 Next cell End Sub
After that you can return to Excel. Select the necessary cells and run our macro through the menu Tools - Macro - Macros (Alt+F8) .
Also, if you replace in the macro code
Likewise, you can perform any operation, such as multiplying by any number.