WallStreetMojo

WallStreetMojo

WallStreetMojo

MENUMENU
  • Free Tutorials
  • Certification Courses
  • Excel VBA All in One Bundle
  • Login
Home » Excel, VBA & Power BI » Learn VBA » VBA Break

VBA Break

Excel VBA BreakPoint

Break is used in VBA when we want a code to stop executing when the given criteria is met, or sometimes the code encounters an error which will show the incorrect value then we need our statement or code to break, there is an inbuilt statement in VBA for break and it is known as EXIT statement.

VBA Break is the pause button for the execution of the code. All the lines of code above the breakpoint will run until it finds the breakpoint in the code.

For your information, below is the sample image of the breakpoint line.

VBA-Break example

In the above image, a red line indicates the breakpoint.

The discovery of the power of VBA comes when we write huge code to execute big projects to get the job done. When we write a considerable amount of code, we need to test those lines of codes to proceed to the next level of coding to ensure our line of code is working as per our objective.

When you test huge code, it takes a lot of time to step through each line, so to run fast to the next level or step of code, we can set the breakpoint and test until the breakpoint and proceed from that breakpoint line by line. In some cases, without putting the breakpoint, we can exit the subprocedure as well.

Why do we need to use it?

Debugging is part and parcel of the coding in any language. Debugging allows us to find the loopholes of the code and fix them. While debugging a large amount of code, we need to run through bug-free lines of codes without wasting much time. Bug-Free code is without any error codes.

Popular Course in this category
Sale
VBA Training (3 Courses, 12+ Projects)
4.6 (247 ratings)
3 Courses | 12 Hands-on Projects | 43+ Hours | Full Lifetime Access | Certificate of Completion
View Course

For example, assume you have 100 lines of code, and you know for sure your first 25 lines of code is bug-free code. But the problem here is when we are testing the code, we need to run from the first line of code, we cannot straight run into the 26th line, so in these cases, we need to set the breakpoint and run through the first 25 lines of code quickly.

By setting the VBA breaking point, you can press the F5 key to run the macro code, and your execution will be completed until the 26th line, and since we applied the breakpoint, it will stop there. From that line onwards, we can debug the code.

How to Apply BreakPoints in VBA?

Breakpoints are very easy to add and remove from the line of codes. We can apply breakpoints in two ways.

  • I am pressing the F9 key by selecting the breakpoint line of code.
  • Click on the left margin of the breakpoint line of code.
You can download this VBA Break Excel Template here – VBA Break Excel Template

Method #1

Now, look at how to set a breakpoint by “Pressing the F9 key by selecting the breakpoint line of code.”

  • Assume you have a considerable code, something like the below line.

apply break points example1.1

  • We have many lines of code here.  Assume you want to set a breakpoint on the 6th line. Place a cursor on the 6th line.

apply break points example1.2

  • After placing the cursor, press the F9 key.

apply break points example1.3

  • As soon as you press an F9 key, you can see a red highlighted line like the below.

apply break points example1.4

  • Now, if you run the code, it will execute until it finds the red line or paused line we have created by pressing the F9 key.

apply breakpoints example1.5

When you run the code, you can see on the left side until the A5 cell values are inserted.

On the right side, we can see the yellow-colored line, it is an indication that the line is about to execute that line of code, but since we have set the breakpoint, it is paused there only.

Method #2

Now, look at how to set a breakpoint using “Click on the left margin of the breakpoint line of code.”

This method also works the same way, but applying is different.

  • As we have seen in the above image, we needed to set the breakpoint on the 6th line. In this method, we need to select a particular line of code here. Instead, we can click on the left margin side of that specific line of code.

apply breakpoints example 2.1

  • It will apply the breakpoint there.

apply breakpoints example 2.2

Like this, we can set the breakpoint to pause the line of codes.

  • We can also set multiple breakpoints either by selecting the line of code and pressing the F9 key or click on the left margin of the line of code.

apply breakpoints example 2.3

You can use the F9 key to toggle the breakpoint on or off.

Recommended Articles

This has been a guide to Excel VBA Break. Here we learn how to apply breakpoint in VBA code using two methods 1) Press F9 Key 2) Click on the left margin of the VBA Code along with examples and a downloadable excel template. Below are some useful excel articles related to VBA –

  • VBA New Line
  • End in VBA Excel
  • Loops in VBA
  • VBA PowerPoint
0 Shares
Share
Tweet
Share
VBA Training (3 Courses, 12+ Projects)
  • 3 Courses
  • 12 Hands-on Projects
  • 43+ Hours
  • Full Lifetime Access
  • Certificate of Completion
LEARN MORE >>
Primary Sidebar
Footer
COMPANY
About
Reviews
Contact
Privacy
Terms of Service
RESOURCES
Blog
Free Courses
Free Tutorials
Investment Banking Tutorials
Financial Modeling Tutorials
Excel Tutorials
Accounting Tutorials
Financial Statement Analysis
COURSES
All Courses
Financial Analyst All in One Course
Investment Banking Course
Financial Modeling Course
Private Equity Course
Venture Capital Course
Excel All in One Course

Copyright © 2021. CFA Institute Does Not Endorse, Promote, Or Warrant The Accuracy Or Quality Of WallStreetMojo. CFA® And Chartered Financial Analyst® Are Registered Trademarks Owned By CFA Institute.
Return to top

WallStreetMojo

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

* Please provide your correct email id. Login details for this Free course will be emailed to you

Book Your One Instructor : One Learner Free Class
Let’s Get Started
Please select the batch
Saturday - Sunday 9 am IST to 5 pm IST
Saturday - Sunday 9 am IST to 5 pm IST

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

WallStreetMojo

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

* Please provide your correct email id. Login details for this Free course will be emailed to you

Login

Forgot Password?

WallStreetMojo

Download VBA Break Excel Template

New Year Offer - VBA Training Course (6 courses, 35+ hours video) View More