I broke VBA

  • Thread starter Thread starter lukecs
  • Start date Start date
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.
 
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?
 
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...
 
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.
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top