When we apply the percentage number format to cells with values, the values are multiplied by 100 to convert them to percentages. This tutorial shows how to format percentages in Excel VBA.
We will apply the percentage number format to range D2:D4 in the following dataset to display the numbers as percentages, not decimals.
We use the following steps:
- Click Developer >> Code >> Visual Basic to open the Visual Basic Editor.
You can also press Alt + F11 to open the Visual Basic Editor.
- In the Visual Basic Editor, open the Insert menu and click the Module option to insert a module.
- Type the following sub-procedure in the module:
Range("D2:D4").NumberFormat = "0.00%"
- Save the procedure and save the workbook as a Macro-Enabled Workbook.
- Click inside the procedure and press F5 to run the code. You can also run the code by clicking the Run Sub/Userform button on the toolbar.
- Click the View Microsoft Excel button on the toolbar to switch to the active worksheet containing the dataset.
You can also press Alt + F11 to switch to the active worksheet.
The values in range D2:D4 of the dataset are displayed as percentages.
This tutorial has explained how to format percentages in Excel VBA. We hope you found the information helpful.