- Excel Macros - Configuring a Macro
- Excel Macros - Debugging a Code
- Excel Macros - UserForms
- Excel Macros - Editing
- Creating a Macro Using VBA Editor
- Excel Macros - Running a Macro
- Assigning Macros to Objects
- Excel Macros - Understanding Codes
- Excel Macros - VBA
- Excel Macros - Relative References
- Excel Macros - Absolute References
- Excel Macros - Security
- Macros in a Single Workbook
- Excel Macros - Creation
- Excel Macros - Overview
- Excel Macros - Home
Excel Macros Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Excel Macros - Editing
You have learnt how to write macro code in VBA editor in the previous chapter. You can edit the macro code, rename a macro and delete a macro.
If you master Excel VBA, writing code or modifying code for a macro is a trivial task. You can edit the macro code however you want. If you want to make only few simple changes in the macro code, you can even copy macro code from one place to another.
Copying a Macro Code
You have created two macros – MyFirstMacro and Button1_Cpck in the macro enabled workbook MyFirstMacro.xlsm. You have created the first macro by recording the steps and the second macro by writing code. You can copy code from the first macro into the second macro.
Open the workbook MyFirstMacro.xlsm.
Cpck the Developer tab on the Ribbon.
Cpck Visual Basic. The Visual Basic editor opens.
Open the code for Module1 (MyFirstMacro macro code) and Module2 (Button1_Cpck () macro code).
Cpck the Window tab on the Ribbon.
Select Tile Horizontally from the dropdown pst.
You can view the code of the two macros in the tiled windows.
Copy the MsgBox pne in the Module2 code.
Paste it above that pne.
Modify the string as −
MsgBox “Hello World!”
Copy the following code from Module1.
Paste it in the Module2 code in between the two MsgBox pnes of code.
Cpck the Save icon to save the code.
Cpck the Button in the Excel sheet. A Message box appears with the message - Hello World! Cpck OK.
The table data appears (according to the code that you copied) and message box appears with message - Best Wishes to You!
You can modify the code in just a few steps. This is the easiest task for a beginner.
Renaming a Macro
Suppose you want to run the edited macro from any worksheet other than the one that has the command button. You can do it irrespective of button cpck by renaming the macro.
Cpck the VIEW tab on the Ribbon.
Cpck Macros.
Select View Macros from the dropdown pst.
The Macro dialog box appears.
Cpck the macro name – Button1_Cpck.
Cpck the Edit button.
The macro code appears in the VBA editor.
Change the name that appears in the Sub pne from Button1_Cpck to RenamedMacro. Leave Sub and parenthesis as they are.
Open the Macro dialog box. The macro name appears as you renamed.
Cpck RenamedMacro.
Cpck the Run button. The macro runs. Now a button cpck is not necessary.
Deleting a Macro
You can delete a macro that you have recorded or coded.
Open the Macros dialog box.
Cpck the macro name.
Cpck the Delete button.
The Delete confirmation message appears.
Cpck Yes if you are sure to delete the macro. Otherwise, cpck No.
Advertisements