Sunday, May 13, 2012

How to Convert Columns to Percent Using VBA


1. Open the Excel 2010 spreadsheet where you want to format a column as a percentage. Once the spreadsheet is open, press 'Alt' and 'F11' to open up the VBA console.
2. Right-click on the first worksheet listed on the left side of the VBA console. Choose 'Module' from the popup menu under 'Insert.' Click on the new module that appears a few lines underneath the worksheet.
3. Place your cursor in the white space on the right side of the VBA console. Type 'Sub ColConv' and press 'Enter.' VBA will automatically add the 'End Sub' command to the code.
4. Place your cursor on the line between the 'Sub' and 'End Sub' commands. Enter the following code into the console:Columns('A:A').SelectSelection.NumberFormat = '0.000%'Change both 'As' to whatever column you want to convert. Change the number of '0s' after the decimal to determine how many decimal places the percentage will show. For example, '0.00%' will display a percentage as '15.55%,' while '0%' will display a percentage as '16%.'
5. Click the 'X' at the top of the VBA console to close it. You can run your macro by clicking the 'Macro' button in the 'Developer' tab. Just choose 'ColConv' from the list and click 'Run' to convert your specified column to a percentage.

Blogger news