VBA: Stop vs Debug.Assert?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,691
Office Version
  1. 365
Platform
  1. Windows
What's the difference between Stop and Debug.Assert in VBA code?

Thanks
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Debug.Assert conditionally suspends code execution, Stop suspends code execution.
 
Upvote 0
No it means you can't use Debug.Assert in VBA.
 
Upvote 0
There is no Assert method for the Debug object in VBA.
VB & VBA in a Nutshell said:
the Debug object in the VBA development environment doesn't support the Assert method.
 
Upvote 0
There is no Assert method for the Debug object in VBA.

Yes, so you said. My question now is why you didn't say that in your first response since I was specifically asking about VBA, not VB. Your answer, that "Debug.Assert conditionally suspends code execution," only applies to VB, not VBA. It would have been more helpful if you had said then that Debug.Assert is not supported in VBA.
 
Upvote 0
Jennifer

To be honest I think I might be as confused as you are, and it was pretty early in the morning when I first posted.:eek:

Also, in post #3 I was referring to what was written in the article you linked too.


Anyway, Debug.Assert does appear to be available in VBA, here's a small example.
Code:
Dim I As Long

    For I = 1 To 10
        Debug.Print I <> 5
        Debug.Assert I <> 5
    Next I
When you run the above code execution will be suspended when I = 5, i.e. I<>5 returns False.
 
Last edited:
Upvote 0
YES! There is a Debug.Assert and it is used to stop the code execution when the condition ceases being true so it is a little bit counter-intuitive.

I prefer to set a watch and break when a condition is true. It is much easier to do so and during debugging I need to be focused on solving the problem, rather than being distracted by checking if my condition should be set this way or the other way round.

PS: Debug.Assert is much less popular than the Debug.Print which is practically in every book I have ever read. I only learned about Debug.Assert a couple of months ago...
 
Upvote 0
Solution

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top