SlideShare a Scribd company logo
1 of 20
Debugging Tools
Debug Macros:-
You may have heard of the technique called debugging before. With
this technique you can find errors in your Excel VBA code before
you execute the code. To show you how to debug a macro, execute
the following steps.
1. Launch the Visual Basic Editor.
2. Create the following incorrect macro:
Incorrect Macro Code.
3. Place your cursor before Private.
4. There are two ways to debug a macro.
 Press F8
or
 Go to Debug Menu and click on Step Into.
Debug your macro. The first line will turn yellow.
5. Press F8 again. The second code line will turn yellow. As long as the
debugger thinks everything is okay, nothing will happen.
6. Press F8 twice. The following error will show up
7. It says that the object doesn't support the property or method.
The Range object has a property called Value. Value isn't spelled
correctly here, so the debugger doesn't recognize the property.
The various debugging resources
available in the VBA Editor
• The Immediate Window is a window in the VBE in which you can enter
commands and view and change the contents of variables while you code
is in Break mode or when no macro code is executing.
• To display the Immediate Window:
– Press CTRL+G
Or
– Choose it from the View menu.
• In the Immediate Window, you can display the value of a variable by using
the “? “command.
Simply type ? followed by the variable name and press Enter.
VBA will display the contents of the variable in the Immediate Window.
Immediate Window
For example:-
?ActiveCell.Address
$A$10
You can also execute VBA commands in the Immediate Window by omitting
the question mark and entering the command followed by the Enter key:
Application.EnableEvents=True
or
Range("A1").Value = 1234
• The Immediate Window won't let you enter VBA code snippets and
execute them together because the Immediate Windows executes what
you enter when you press the Enter key.
• However, you can combine several "logical" lines of code in to a single
"physical" line of code using the ':' character, and execute this entire
command.
Example:-
First we record a simple macro to print random no’s between 1
to 10. and create a chart of that data.
Developer tab
Start
Recording
Select the range A1 to F5
Type formula
=rand()*10
1
2
3
4
Click on Insert
Menu.
Click on Charts
Click on 3-D
column Chart.
Chart will appears on sheet.
Click on Stop Button
• Now Open the VBE(Press Alt+F11 on excel sheet).
• It shows all coding.
Now we see the working of Immediate window
•Go to View Menu Click on Immediate window.
OR
•Press Ctrl+G
Now we Execute some code by using immediate window.(VBE allows us to
execute VBA code line by line.)
Type code and press Enter it
Shows the O/P. on Excel sheet.
• We execute one more code.
Code in Immediate window
is to Add 3-D chart in Excel
sheet
It Shows random
no’s between 1 to
10
Break Points:-
• A break point is a setting on a line of code that tells VBA to pause
execution immediately before that line of code is executed. Code
execution is placed in what is called break mode.
When VBA is in break mode, you can enter commands in to the
Immediate Window to display or change the values of variables.
To put a break point on a line of code:-
Place the cursor on that line and press F9
or
Choose "Toggle Breakpoint" from the Debug menu.
To remove a break point:-
Place the cursor on that line and press F9
or
Choose "Toggle Breakpoint" from the Debug menu.
When a line contains a break point, it is displayed with a brick
colored background. Immediately before this line of code is
executed, it will appear with a yellow background. Remember, when
a break point is encountered, code execution is paused but that line
of code has not yet executed.
You cannot place break points on blank lines, comment lines, or
variable declaration lines (lines with Dimstatements).
After a break point is encountered, you can resume normal code
execution by pressing F5 or choosing "Continue" from the Run
menu.
**Note that break points are not saved in the workbook file. If you
close the file, all break points are removed. Breakpoints are
preserved as long as the file is open.
Stepping Through Code:-
Normally, your code runs unattended. It executes until its logical
end. However, when you are testing code, it is often useful to step
through the code line by line, watching each line of code take effect.
This makes it easy to determine exactly what line is causing incorrect
behavior.
You can step through code line by line:-
Press F8 key to start the procedure in which the cursor is, or
when VBA is paused at a break point.
 Pressing F8 causes VBA to execute each line one at a time.
 Highlighting the next line of code in yellow.
Note, the highlighted line is the line of code that will execute when
you press F8. It has not yet been executed.
• If your procedure calls another procedure, pressing F8 will cause
VBA to step inside that procedure and execute it line by line.
• You can use SHIFT+F8 to "Step Over" the procedure call. This
means that the entire called procedure is executed as one line of
code. This can make debugging simpler if you are confident that
the problem does not lie within a called procedure.
• When you are in a called procedure, you can use CTRL+SHIFT+F8 to
"Step Out" of the current procedure. This causes VBA to execute
until the end of the procedure is reached (an End Sub or Exit
Sub statement) and then stop at the line of code immediately
following the line which called the procedure.
Watch Window:-
• The Watch Window allows you to "watch" a specific variable or
expression and cause code execution to pause and enter break
mode when the value of that variable or expression is True (non-
zero) or whenever that variable is changed.
• To display the Watch Window,
– Choose it from the View menu.
• To create a new watch,
– Choose Add Watch from the Debug menu.
This will display the Add Watch window, shown below.
VISUAL

More Related Content

What's hot (9)

Access tips access and sql part 6 dynamic reports
Access tips  access and sql part 6  dynamic reportsAccess tips  access and sql part 6  dynamic reports
Access tips access and sql part 6 dynamic reports
 
Learn Excel Macro
Learn Excel Macro  Learn Excel Macro
Learn Excel Macro
 
Vba
Vba Vba
Vba
 
E learning excel vba programming lesson 2
E learning excel vba programming  lesson 2E learning excel vba programming  lesson 2
E learning excel vba programming lesson 2
 
Updating the UC TCA using Adobe
Updating the UC TCA using AdobeUpdating the UC TCA using Adobe
Updating the UC TCA using Adobe
 
Vba introduction
Vba introductionVba introduction
Vba introduction
 
Programming Environment in Matlab
Programming Environment in MatlabProgramming Environment in Matlab
Programming Environment in Matlab
 
Gutmacher practical-coding-examples-for-sourcers-sc18 atl
Gutmacher practical-coding-examples-for-sourcers-sc18 atlGutmacher practical-coding-examples-for-sourcers-sc18 atl
Gutmacher practical-coding-examples-for-sourcers-sc18 atl
 
25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manual25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manual
 

Similar to VISUAL

10.USING THE ECLIPSE DEBUGGERupdated 8618This t.docx
10.USING THE ECLIPSE DEBUGGERupdated 8618This t.docx10.USING THE ECLIPSE DEBUGGERupdated 8618This t.docx
10.USING THE ECLIPSE DEBUGGERupdated 8618This t.docx
paynetawnya
 
Abapdebuggingfrombasictoadvance 140214043218-phpapp01
Abapdebuggingfrombasictoadvance 140214043218-phpapp01Abapdebuggingfrombasictoadvance 140214043218-phpapp01
Abapdebuggingfrombasictoadvance 140214043218-phpapp01
IT TRAINER
 
Autocad excel vba
Autocad excel vbaAutocad excel vba
Autocad excel vba
rjg_vijay
 

Similar to VISUAL (20)

Macros
MacrosMacros
Macros
 
Debugger & Profiler in NetBeans
Debugger & Profiler in NetBeansDebugger & Profiler in NetBeans
Debugger & Profiler in NetBeans
 
Error handling and debugging in vb
Error handling and debugging in vbError handling and debugging in vb
Error handling and debugging in vb
 
VBA Tips
VBA TipsVBA Tips
VBA Tips
 
2 front panel
2  front panel2  front panel
2 front panel
 
Excel vba
Excel vbaExcel vba
Excel vba
 
Excel VBA.pptx
Excel VBA.pptxExcel VBA.pptx
Excel VBA.pptx
 
Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1
 
Learn VBA Training & Advance Excel Courses in Delhi
Learn VBA Training & Advance Excel Courses in DelhiLearn VBA Training & Advance Excel Courses in Delhi
Learn VBA Training & Advance Excel Courses in Delhi
 
Visual Logic User Guide
Visual Logic User GuideVisual Logic User Guide
Visual Logic User Guide
 
10.USING THE ECLIPSE DEBUGGERupdated 8618This t.docx
10.USING THE ECLIPSE DEBUGGERupdated 8618This t.docx10.USING THE ECLIPSE DEBUGGERupdated 8618This t.docx
10.USING THE ECLIPSE DEBUGGERupdated 8618This t.docx
 
Tugas testing
Tugas testingTugas testing
Tugas testing
 
Basic Debugging
Basic DebuggingBasic Debugging
Basic Debugging
 
Abapdebuggingfrombasictoadvance 140214043218-phpapp01
Abapdebuggingfrombasictoadvance 140214043218-phpapp01Abapdebuggingfrombasictoadvance 140214043218-phpapp01
Abapdebuggingfrombasictoadvance 140214043218-phpapp01
 
Online Advance Excel & VBA Training in India
 Online Advance Excel & VBA Training in India Online Advance Excel & VBA Training in India
Online Advance Excel & VBA Training in India
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Introduction To Excel 2007 Macros
Introduction To Excel 2007 MacrosIntroduction To Excel 2007 Macros
Introduction To Excel 2007 Macros
 
Autocad excel vba
Autocad excel vbaAutocad excel vba
Autocad excel vba
 
ID E's features
ID E's featuresID E's features
ID E's features
 

Recently uploaded

SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 

Recently uploaded (20)

8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 

VISUAL

  • 2. Debug Macros:- You may have heard of the technique called debugging before. With this technique you can find errors in your Excel VBA code before you execute the code. To show you how to debug a macro, execute the following steps. 1. Launch the Visual Basic Editor. 2. Create the following incorrect macro:
  • 4. 3. Place your cursor before Private. 4. There are two ways to debug a macro.  Press F8 or  Go to Debug Menu and click on Step Into. Debug your macro. The first line will turn yellow.
  • 5. 5. Press F8 again. The second code line will turn yellow. As long as the debugger thinks everything is okay, nothing will happen. 6. Press F8 twice. The following error will show up 7. It says that the object doesn't support the property or method. The Range object has a property called Value. Value isn't spelled correctly here, so the debugger doesn't recognize the property.
  • 6. The various debugging resources available in the VBA Editor
  • 7. • The Immediate Window is a window in the VBE in which you can enter commands and view and change the contents of variables while you code is in Break mode or when no macro code is executing. • To display the Immediate Window: – Press CTRL+G Or – Choose it from the View menu. • In the Immediate Window, you can display the value of a variable by using the “? “command. Simply type ? followed by the variable name and press Enter. VBA will display the contents of the variable in the Immediate Window. Immediate Window
  • 8. For example:- ?ActiveCell.Address $A$10 You can also execute VBA commands in the Immediate Window by omitting the question mark and entering the command followed by the Enter key: Application.EnableEvents=True or Range("A1").Value = 1234 • The Immediate Window won't let you enter VBA code snippets and execute them together because the Immediate Windows executes what you enter when you press the Enter key. • However, you can combine several "logical" lines of code in to a single "physical" line of code using the ':' character, and execute this entire command.
  • 9. Example:- First we record a simple macro to print random no’s between 1 to 10. and create a chart of that data. Developer tab Start Recording Select the range A1 to F5 Type formula =rand()*10 1 2 3 4
  • 10. Click on Insert Menu. Click on Charts Click on 3-D column Chart.
  • 11. Chart will appears on sheet. Click on Stop Button
  • 12. • Now Open the VBE(Press Alt+F11 on excel sheet). • It shows all coding. Now we see the working of Immediate window •Go to View Menu Click on Immediate window. OR •Press Ctrl+G
  • 13. Now we Execute some code by using immediate window.(VBE allows us to execute VBA code line by line.) Type code and press Enter it Shows the O/P. on Excel sheet.
  • 14. • We execute one more code. Code in Immediate window is to Add 3-D chart in Excel sheet It Shows random no’s between 1 to 10
  • 15. Break Points:- • A break point is a setting on a line of code that tells VBA to pause execution immediately before that line of code is executed. Code execution is placed in what is called break mode. When VBA is in break mode, you can enter commands in to the Immediate Window to display or change the values of variables. To put a break point on a line of code:- Place the cursor on that line and press F9 or Choose "Toggle Breakpoint" from the Debug menu. To remove a break point:- Place the cursor on that line and press F9 or Choose "Toggle Breakpoint" from the Debug menu.
  • 16. When a line contains a break point, it is displayed with a brick colored background. Immediately before this line of code is executed, it will appear with a yellow background. Remember, when a break point is encountered, code execution is paused but that line of code has not yet executed. You cannot place break points on blank lines, comment lines, or variable declaration lines (lines with Dimstatements). After a break point is encountered, you can resume normal code execution by pressing F5 or choosing "Continue" from the Run menu. **Note that break points are not saved in the workbook file. If you close the file, all break points are removed. Breakpoints are preserved as long as the file is open.
  • 17. Stepping Through Code:- Normally, your code runs unattended. It executes until its logical end. However, when you are testing code, it is often useful to step through the code line by line, watching each line of code take effect. This makes it easy to determine exactly what line is causing incorrect behavior. You can step through code line by line:- Press F8 key to start the procedure in which the cursor is, or when VBA is paused at a break point.  Pressing F8 causes VBA to execute each line one at a time.  Highlighting the next line of code in yellow. Note, the highlighted line is the line of code that will execute when you press F8. It has not yet been executed.
  • 18. • If your procedure calls another procedure, pressing F8 will cause VBA to step inside that procedure and execute it line by line. • You can use SHIFT+F8 to "Step Over" the procedure call. This means that the entire called procedure is executed as one line of code. This can make debugging simpler if you are confident that the problem does not lie within a called procedure. • When you are in a called procedure, you can use CTRL+SHIFT+F8 to "Step Out" of the current procedure. This causes VBA to execute until the end of the procedure is reached (an End Sub or Exit Sub statement) and then stop at the line of code immediately following the line which called the procedure.
  • 19. Watch Window:- • The Watch Window allows you to "watch" a specific variable or expression and cause code execution to pause and enter break mode when the value of that variable or expression is True (non- zero) or whenever that variable is changed. • To display the Watch Window, – Choose it from the View menu. • To create a new watch, – Choose Add Watch from the Debug menu. This will display the Add Watch window, shown below.