How to Edit Macros in Excel’s Visual Basic Editor
Click the View Macros option on the Macros command button on the View tab or press Alt+WMV or Alt+F8.
This action opens the Macro dialog box showing all the names of the macros that you’ve defined in the workbook and in your Personal Macro Workbook.
Click the name of the macro that you want to edit in the Macro Name list box and then click the Edit button.
This action opens the Visual Basic Editor with the code for your macro displayed in the Code window unless you select the name of a macro saved in the Personal Macro Workbook and this workbook is still hidden.
In that case, Excel displays an Alert dialog box telling you that you can’t edit a hidden macro and informing you that you need to unhide this workbook. You then need to click OK in the Alert dialog box, press Escape to close the Macro dialog box, and unhide the Personal Macro Workbook.
After you have the lines of code for the macro displayed in the Code window in the Visual Basic Editor, you can edit any of its statements as needed. If you want to obtain a printout of the lines of code in your macro before you begin making changes, choose File→Print on the Visual Basic Editor menu bar or press Ctrl+P.
This action opens a Print – VBAProject dialog box with the Current Module option button selected in the Range section and the Code check box selected in the Print What section so that you can go ahead and click OK to have Excel print all the statements in the macro.
When editing the macro’s commands, remember that you can use the Edit→Undo (Ctrl+Z) command to undo any deletion that you make by mistake.
Edit the statements in the Code window of the Visual Basic Editor as needed.
After you finish editing the macro, you’re ready to return to your spreadsheet, where you can test out the modified macro and make sure that you haven’t added some wacky, unwanted command to the macro or, even worse, crippled it so that it no longer runs at all.
Click the View Microsoft Excel button at the beginning of the Standard toolbar or click the workbook’s minimized button on the Windows taskbar.
Select an appropriate or safe place in which to test your modified macro and then run it, either by pressing its shortcut keys or by pressing Alt+F8, clicking it in the Macro list box, and then clicking the Run button.
If something doesn’t work as intended or if the macro doesn’t work at all, you need to return to the Visual Basic Editor and find and correct your error(s). Click the Visual Basic command button on the Developer tab of the Ribbon (Alt+LV) to return to the Visual Basic Editor and have a try at editing the code one more time.
If everything checks out and runs as planned, you need to save your changes as outlined in Step 5.
Click the Save button on the Quick Access toolbar to save the changes to the modified macro if it’s stored as part of the current workbook.
If you modified a global macro saved as part of the Personal Macro Workbook, you have to exit Excel in order to save your changes to the macro. When you click the Excel program window’s Close button or press Alt+FX or Alt+F4, Excel displays an alert dialog box asking whether you want to save the changes you made to the personal.xlsb file.
Click the Yes button to save your macro modifications as you close down Excel.