I broke VBA

L

lukecs

heres my sub

Sub testing2()
With Application
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
End With
Range("F1").Value = 6
Debug.Print "ran"
End Sub

It does the first statement but will not execute the second. Nothing
else is open, nothing else is executed. What could possible be going
on. Range F1 does get updated to 6 but the debug line or for that
matter anything after the Range("F1").Value line does not run. Has
anyone ever had this problem. tried restarting excel but haven't
tried running it on another machine. Issue only happens on one
workbook.
 
T

TomPl

What else do you think it is supposed to do besides set the value in F1 = 6
and print the work "ran" in the Immediate window?
 
T

The Code Cage Team

I suspect you haven't got the immediates window visible when you ru
that code from the VBE, all its supposed to do is show 6 in F1 and sho
the word "run" in the immediates window

--
The Code Cage Tea

Regards,
The Code Cage Team
www.thecodecage.co
 
S

Sheeloo

By second statement you mean - Debug.Print "ran"?
What are you expecting it to do?

It is working fine. Debug output goes to Immediate Window...
 
L

lukecs

By second statement you mean - Debug.Print "ran"?
What are you expecting it to do?

It is working fine. Debug output goes to Immediate Window...

ya the VBA exits without an error at Debug.print "ran". It exits
right after changing the range no matter what the code before or
after. So even if I wrap it with on error goto error_exit or
something like that it will still exit.

hmmmm
I think I may have figured out the issue. A volatile UDF was causing
the error. So when the workbook updated a value it calculated the UDF
and then caused an error in the function. Its just strange that it
exited the sub that I ran this code from without an error message. I
guess I need to practice a little more robust error trapping in my
UDF's.

The error is caused by attempting to use application.evaluate in a UDF
that evaluates another UDF that does not properly return an error.
Its been corrected by checking for errors in the UDF and returning
CVErr(xlErrNA) if there is an error.

Thanks for the assistance hopefully provided enough info that it may
help someone else in the future.
 
R

Ron Rosenfeld

heres my sub

Sub testing2()
With Application
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
End With
Range("F1").Value = 6
Debug.Print "ran"
End Sub

It does the first statement but will not execute the second. Nothing
else is open, nothing else is executed. What could possible be going
on. Range F1 does get updated to 6 but the debug line or for that
matter anything after the Range("F1").Value line does not run. Has
anyone ever had this problem. tried restarting excel but haven't
tried running it on another machine. Issue only happens on one
workbook.

It works fine for me, in a regular module.

How do you know that the debug.print line did not run?
--ron
 
Top