Here’s an overview of using the Macros option to edit macros in a sheet.
How to Unhide a Macro in a Personal Workbook
Your macros can be saved anywhere. If the personal workbook is hidden, you may have to unhide it first.
- Click on the View tab.
- From the Window group, select Unhide.
- You will see an Unhide dialog box.
- Select the personal workbook and click on OK.
- You will see the personal workbook with macros in it. You can edit macros whenever you want.
Method 1 – Using Keyboard Shortcuts to Edit Macros in Excel
Case 1.1 – Applying a Keyboard Shortcut to Open the Macros Dialog Box in Excel
- Press Alt + F8 on your keyboard. A Macro dialog box will appear.
- Select any macro from the Macro name list.
- Click on Edit.
- This will take you to the VBA editor.
- Edit the code in the window.
Case 1.2 – Opening the Excel VBA Editor Directly Using Keyboard Shortcuts
- Press Alt + F11 to open the VBA editor.
- Choose a module and double-click on it.
- Your VBA Editor is open, and you can edit the macros easily.
Read More: How to Remove Macros from Excel
Method 2 – Editing VBA Code with the Macros Command in Excel
- Go to the View tab. You will see the Macros button to the right.
- Otherwise, you will find the Macros option in the Developer tab
- Click on Macros.
- The Macro dialog box will open.
- Choose any macro from the Macro name list and then click on Edit.
- You will get your selected macro. You can start editing.
Read More: How to Save Macros in Excel Permanently
Debug and Run Excel VBA Macros after Editing
Take a look at this dataset which shows the Marital Status’ of 7 persons in a group with their Names.
- We have some blank cells in the dataset. Our goal was to fill those empty cells with the word Unmarried.
- We provided the following VBA code.
Sub FindNext_empty_value()
Dim search_value As Variant
search_value = InputBox("Which Value Do You Want to Search ?", "Search Value")
If StrPtr(search_value) = 0 Then
Exit Sub
End If
Application.DisplayAlerts = False
Dim search_range As Range
On Error Resume Next
Set search_range = Application.InputBox("Select Your Range of Cells", "Search Range", Type:=8)
On Error GoTo 0
Application.DisplayAlerts = True
If search_range Is Nothing Then
Exit Sub
End If
Dim FindRng As Range
Set FindRng = search_range.Find(what:=search_value)
counter = 0
Do
counter = counter + 1
FindRng.value = "Unmarried"
Set FindRng = search_range.FindNext(FindRng)
Loop While Not FindRng Is Nothing
MsgBox "Total " & counter & " empty cells were replaced with: Unmarried"
End Sub
- After we implemented that code, our result was like the following screenshot.
We will fill the blank cells with the word Single.
- Press the Alt + F8 on your keyboard to open the Macro dialog box.
- Select FindNext_empty_value.
- Click on Edit.
- The VBA Editor will open.
- We removed the Unmarried word from the code.
- From the Debug tab, select Compile VBAProject.
- This will show an error as we didn’t give any values.
- Change it to Single like the following screenshot.
- From the Debug menu bar, select Compile VBAProject. This time there will be no error.
- Press Ctrl + S on your keyboard to save it and then close the VBA Editor.
- Press Alt+F8 on your keyboard and select FindNext_empty_value.
- Click on Run.
- You will get the Search Value box.
- Leave the field empty as we are searching for blank cells and click on OK.
- Select the range of cells from the dataset in the Search Range dialog box.
- Click on OK.
- We have successfully edited our code, and this is working fine.
Things to Remember
- If you do not get the macro-enabled Excel file from a trusted source, do not enable the macro content. There might be malicious codes.
- Make a copy of the VBA Macro so that you can easily find the code whenever you need it.
Download the Practice Workbook
Related Articles
- How to Save VBA Code in Excel
- Using Macro Recorder in Excel
- How to Record a Macro in Excel
- Excel Macro Shortcut Key
- 25 VBA Macro Example for Enhanced Productivity
- Types of VBA Macros in Excel
- How to Use Excel VBA to Run Macro When Cell Value Changes
- Excel VBA to Pause and Resume Macro
- Excel Macro Enabled Workbook