Home > Macros > Basics > Troubleshoot

Excel Macro Troubleshooting Tips

Troubleshoot a simple Excel macro, if an error message appears. Use the Debug button to find and fix a small problem in the code. How to fix the problem in the F8 key stops working while stepping through a macro. What to do if the Project Explorer list is missing

Reading an Excel macro you wrote 5 years ago


Error Message Debug Button

Occasionally, when you try to run a macro, an error message will appear, such as the "Run-Time Error '9': Subscript Out of Range" error shown below.

On this error message, there are 3 buttons available -- End, Debug and Help.

  • To stop the macro, click the End button.
  • To get information about the error, click Help. In this case, you would end up on page on the Microsoft website, with a list of possible causes and solutions for the Subscript Out of Range error.
  • To go to the VBE and try to solve the problem, click the Debug button.

    run-time error 9

Debug the Macro

In this example, a macro was recorded, to go to a sheet named "Main", then select cell C3 on that sheet. When the macro is run, the above error message appears.

Here is the VBA code, for the GoToMainSheet macro:

Sub GoToMainSheet()
' GoToMainSheet Macro
End Sub

We'll use the Debug button, to troubleshoot the problem:

  • In the error message, click the Debug button
  • The VBE opens, showing the GoToMain Sheet macro, and a line of code is highlighted in yellow, with a yellow arrow n the margin at the left.
  • line of code highlighted in yellow
  • Excel showed the error message, because it can't complete the highlighted line of code.
  • Look in the Project Explorer window, and check the list of sheets for the active workbook.
  • There are 3 sheets, named "Intro", "Sheet2" and "Sheet3" -- there isn't a sheet named "Main"
  • check list of sheets

We'll stop the debugger, and fix the code.

  • On the VBE Toolbar, click the Reset button
  • reset button on toolbar

The code stops running, and the yellow highlighting disappears.

Fix the Code

Next, you'll edit the code, to change the sheet name.

Solution 1: Not Recommended

  • In the line of code, you could replace "Main" with "Intro", which is the current name of the first sheet in the workbook.
  • However, with that solution, the code could show an error again, if anyone changes the sheet name in the future.
  • This is not the best solution

Solution 2: Recommended

  • Instead of using the name from the Sheet tab, we'll use the sheet's Code Name. It is much less likely to be changed, by anyone other than the programmer..
  • In the Project Explorer, you can see the sheet's Code Name, followed by the name that appears on the sheet tab.
  • check list of sheets

  • The first sheet's Code Name is "Sheet1", so change the code to use that name.
  • This solution is better, because the code will continue to run, even if the name on the sheet tab is changed.

Save the Changes and Test the Macro

  • On the VBE Toolbar, click the Save button, then close the VBE window, and return to Excel
  • Run the macro again, and it should work correctly, without showing an error.

F8 Key Stops Working

When debugging Excel VBA code, you can use the F8 key, or the Step Into command, to step through the code, one line at a time.

regist add dword

However, in Excel 2010 or later versions, you might encounter the problem where the F8 key (or Step Into) stops working, part way through a procedure.

Sometimes, this occurs after the code opens another file. Instead of stopping at the next line of code, it runs to the end of the procedure, or to the next breakpoint.

Change the Registry

To fix this problem, you can make the following change in the Registry. As always, make a backup of the Registry, before making any changes, and try this at your own risk!

Thanks to Ross Connell, for sharing this solution, that he learned from Microsoft Support.

The registry change affects RPC Debugging, and you can read more about it on the Microsoft website:

1) Make a Backup

Before you make any changes to the registry, be sure to do a backup first!

2) Find Registry Key

Next, open the Registry, and go to the applicable VBA key, based on your version of Office and Window

  • For 32-bit Office on 64-bit Window go to registry key:
  • For 32-bit Office on 32-bit Window go to registry key:
  • For 64-bit Office on 64-bit Windows go to registry key:

What To Do Next

  • If you found the applicable VBA key, go to step 3, where you will create a DWORD.
  • If you did NOT find the key, try the solutions in the next section, to search the registry or create the key manually.

No VBA Key in Registry

If you can't find a VBA key in the expected location, try one of the following solutions

1. Search the Registry

Try this solution first - it's easier! (Thanks to Peter Tanner for this tip)

  • In the Registry, right-click on the HKEY_LOCAL_MACHINE folder
  • In the pop-up menu, click Find
  • In the Find box, enter: Microsoft\VBA
  • Click the Find Next button

If that didn't work, try the next solution, below.

search for microsoft vba folder in registry

2. Create the Key Manually

If you can't find the Microsoft\VBA key anywhere in the Registry, follow the steps below, to create the key manually. (Thanks to Ross Connell, for sharing this additional tip)

  • First, find the folder where the VBA key should be located, based on your version of Office and Windows. (See the list above)
  • In the list at the left, select that folder, to see its contents
  • Next, right-click in the right pane of the window, where the contents are listed.
  • Then, in the pop-up menu, click New, then click Key

right-click to create a new key

  • Next, rename the new key as VBA
  • Then, in the list at the left, select the new VBA key, to see its contents

3) Create DWORD in VBA Key

Finally, follow these steps, to create the DWORD (or QWORD) in the VBA key.

  • First, right-click in the right pane of the window, where the contents are listed.
  • Then, in the pop-up menu, click New
  • In the pop-up menu, click DWORD or QWORD, depending on your version of Office

right-click to create a new key

  • Next, name the DWORD (or QWORD) as DisableOrpcDebugging7
  • Right-click the DWORD (or QWORD), and click Modify
  • Change Value Data to 1, and leave the other settings as they are
  • Then, click the OK button, to complete the changes

edit the DWORD

View New Item in Registry

The completed DWORD or QWORD will appear in the Registry.

For example, this screen shot shows a DWORD

completed DWORD

This screen shot shows a QWORD, in a manually created VBA folder

completed QWORD

4) Close Registry

After you finish the steps to create the new DWORD or QWORD in the Microsoft\VBA key, follow these steps:

  • Close the Registry
  • Re-open Excel
  • Test the F8 key, to see if it now works correctly, stepping through the code, and stopping at each line.

Project Explorer Folders Missing

When you work in the Visual Basic Editor, the Project Explorer is usually visible, showing a list of all the open VBA projects.

Click the + or - button at the left of a project name, to open and close the list of objects for that project.

regist add dword

NOTE: If a project is protected, and hasn't been unlocked during the current session, you will be prompted for a password when you click the + button.

regist add dword

Show Folder Contents

Then, click the + or - button at the left of a folder name, to open and close the list of objects for that folder.

regist add dword

Folders Are Missing

Occasionally, the project explorer folders might disappear, and an alphabetical list of the workbook's objects appears below the project name.

regist add dword

To show the objects grouped into folders again, follow these steps:

  1. Click on the project name, for an unlocked project
  2. In the toolbar at the top of the Project Explorer window, click the Toggle Folders button.

The folders will reappear for all projects, with objects groups into folders.

regist add dword

Get Sample File

Debug Button: To test the VBA debugging steps, get the Error Message Debug Button sample file. The zipped Excel file is in xlsm format, and contains the macro named GoToMainSheet. To test the macro, be sure to enable macros when you open the workbook

More Tutorials

Getting Started with Excel Macros

FAQs, Excel VBA, Excel Macros  

Adding Code to an Excel Workbook

Worksheet Macro Buttons

Create a Worksheet List Box

Last updated: January 26, 2023 11:32 AM