How to Edit Macros in Excel (2 Ideal Methods)

Here’s an overview of using the Macros option to edit macros in a sheet.

How to Edit Macros in Excel


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.

Selecting Unhide Command from View Tab

  • You will see an Unhide dialog box.
  • Select the personal workbook and click on OK.

Choosing Workbook Name in Unhide Box

  • 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.

Opening Macro Dialog Box

  • Select any macro from the Macro name list.

Selecting Macro Name

  • Click on Edit.

Choosing Edit Option in Macro Window

  • This will take you to the VBA editor.

Editing Code in 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.

Opening VBA Editor Window

  • Choose a module and double-click on it.

Choosing Module to Edit Macro in Excel

  • 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.

Selecting Macros from View Tab

  • Otherwise, you will find the Macros option in the Developer tab

Selecting Macros from Developer Tab

  • Click on Macros.
  • The Macro dialog box will open.

Opening Macro Dialog Box to Edit Macos in Excel

  • Choose any macro from the Macro name list and then click on Edit.

How to Edit Macros in Excel

  • You will get your selected macro. You can start editing.

Editing Macros in VBA Editor

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.

Dataset to Run Macros

  • 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

Initial VBA Macro Code

  • After we implemented that code, our result was like the following screenshot.

Output after Running Code

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.

Selecting Macro Name with Edit Option

  • The VBA Editor will open.
  • We removed the Unmarried word from the code.

Edit Macros in VBA Editor

  • From the Debug tab, select Compile VBAProject.

Debugging Code

  • This will show an error as we didn’t give any values.

Debugging Code

  • Change it to Single like the following screenshot.

Editing Macros

  • 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.

Running Selected Macro

  • You will get the Search Value box.
  • Leave the field empty as we are searching for blank cells and click on OK.

Keeping Search Value Blank

  • Select the range of cells from the dataset in the Search Range dialog box.

Providing Cell Range in Search Range Dialog Box

  • Click on OK.
  • We have successfully edited our code, and this is working fine.

Final Output after Editing Macros in Excel


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

Get FREE Advanced Excel Exercises with Solutions!
A.N.M. Mohaimen Shanto
A.N.M. Mohaimen Shanto

A.N.M. Mohaimen Shanto, a B.Sc. in Computer Science and Engineering from Daffodil International University, boasts two years of experience as a Project Manager at Exceldemy. He authored 90+ articles and led teams as a Team Leader, meticulously reviewing over a thousand articles. Currently, he focuses on enhancing article quality. His passion lies in Excel VBA, Data Science, and SEO, where he enjoys simplifying complex ideas to facilitate learning and growth. His journey mirrors Exceldemy's dedication to excellence and... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo