Debug Code in Excel VBA

Home/Excel VBA/Debug Code in Excel VBA
Introduction

When you are writing the program you may want to test whether particular statement is working fine. Debug Code in Excel VBA is the one of important task while writing programs, it helps you in troubleshooting your code.

PREMIUM TEMPLATES LIMITED TIME OFFER

ON SALE80% OFF

50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates


VBA provides several options for debugging VBA code:

Run the Procedure

place the cursor in the procedure which you want to run and Press F5 or click on the run button. It will execute that particular procedure/macro.

Stepping through you code

Place your cursor in the procedure which you want to debug:

You can step through your code line by line by pressing F8. It will take through you by line by line and you can see the result/action of the statement wile passing that particular line.

Break Point

You can run the code from one particular statement to another By placing the Break Points. Place the cursor at the line which you want to place the Break Point and press F9, it will place the break point. if you run the code by pressing F5, it will start executing the procedure and stops at the Break Point. To toggle the break point you can press the F9 again.

Alternatively you can use stop statement in the code, if you start executing the code, it will stops at stop statement in the code.

Debug statement and Immediate Window

You can select the ‘Immediate Window’ from the View menu to see the immediate Window.

It is one of the most usefull commands in the vba debugging tasks, you can use Debug.Print statement to print the result of any variable or any text in the Immediate Window

Locals Window

You can select the ‘Local Window’ from the View menu to see the Local Window.

You can see all available variable in the procedure which you are debugging by step by step.

Watch Window

When you are stepping through the procedure You can select a variable or object and right click on it to see all properties and its values in the watch window.

You will use the above methods while debugging your program, following are few short-cut key which helps you to fasten the debugging activity:

ShortKeys

Action

F4

Displays Properties Window

F5

Run/Execute the Active Procedure

F8

Step By Step Debugging

Shift +F8

Execute the calling procedure in one step

F9

Toggle Breakpoint

 CTRL+SHIFT+F9

Clear all breakpoints

SHIFT+F9

Quick Watch

F10

Activate Menu Bar

Debug Code in Excel VBA – Screen-shot

Below is the sample screen-shot of the debugging process:
Debug Code in Excel VBA

LIMITED TIME OFFER
By |March 3rd, 2013|Excel VBA|2 Comments

About the Author:

PNRao is a passionate business analyst and having close to 10 years of experience in Data Mining, Data Analysis and Application Development. This blog is his passion to learn new skills and share his knowledge to make you expertise in Data Analysis (Excel, VBA, SQL, SAS, Statistical Methods, Market Research Methodologies and Data Analysis Techniques).

2 Comments

  1. joe November 9, 2013 at 10:32 PM - Reply

    Excellent website for Excel VBA!

    This page http://mongopono.ru/excel-vba/debug-code/ has one repeating word: “you”

    You you will use the above methods while debugging your program, following are few short-cut key which helps you to fasten the debugging activity:

    • PNRao November 10, 2013 at 1:32 AM - Reply

      Thanks Joe, changed it!

      Regards-PNRao!

Leave A Comment


Related pages


vba copy sheet to new workbookapplication wait excel vbaexcel spreadsheet protectionexcel vba chartshighlight duplicatesworksheet unprotectexcel create macroshow to unlock an excel spreadsheetexcel vba activecell.addressunhide worksheet excel 2010set activesheetmacro delete rows based on cell valueppt schedule templatevisual basic checkboxvba examples for excel 2007vlookup templateunhide row 1 in excel 2010excel vba cells rangeexcel vba programming for dummies free downloadsas find duplicatesexcel 2010 delete duplicatescheck excel for duplicatescompile data from multiple excel worksheetsmacro excel vbavba output to text fileprogrammer interview questions and answersexcel templates for tracking projectssql ddl dml dcl commandspivot table explanationinsert combo box excelcheckbox vba excelwhile loop in excel macrovlookup and functionvlook up tutorialvba pivot table refreshif statements excellarrange alphabetically in excelvba button excelvba fileexcel gantt chart template 2007listbox in accessproject charter template excelmessage box excel vbaexcel adjust row heightworkbook vbaarrays in excelcreate calculator in excelactivecell.rowmacro for vlookupcombine data from multiple excel fileshlookup excel examplepassword protected excel sheetexecutive dashboard templatesvba close workbookexcel formula for namesexcel bubble chartvba trickscollections in vbaexcel compound if statementvba excel left functionexcel vba combobox control sourcehow to create macros in excel 2003excel joining cellsexcel vba copy rangecreating pivot table in excel 2007interview questions on vblook up formula in excelhow to sort alphabetically in excelexample of vlookup formula in excelexcel macro to hide rowshow to amalgamate excel spreadsheetsms access docmd findrecordproject planning spreadsheetcombobox macrovba entirecolumncomplicated excel functionscreating macros in excel 2007create formula in excel vba