"Out of Context" Message?

  • Thread starter Thread starter Mac Lingo
  • Start date Start date
M

Mac Lingo

When I execute the following line of VB Macro code
ActiveSheet.Cells(2,1) = "Hi"

the computer seems to stop processing and all the variables I am watching in
the
"Watches" Screen have their Value change to "<Out of Context>.

Anyone know what's going on? I'm kind of at my wit's end trying to figure
this one out. "Out of context" is not even defined in their help file or
Knowledge Base.

Thanks,
Capt Mac
 
I can't replicate the problem. Can you post the rest of your code and
identify the variables of interest?

"Out of context" generally means that the variable has gone out of scope.
 
Function A(ARG)
i = 1
ActiveSheet.Cells(2, 1) = "Hi"
i = 2
End Function

The Execution of the "ActiveSheet...." line is the point that the values (of
I in the Watch window become "Out of context".

Thanks,
Mac
 
Perhaps you are calling the function from the worksheet, in which case it
fails on the second line.

A worksheet function cannot make any changes to the worksheet; it can only
return a value to the calling cell.
 
Missing Information from the Problem - The VB Macro is calle as a FUNCTION
being
called from the spreadsheet.

The Solution: - A Rule: You CAN'T change the enviornment a Function is being
called from. I suppose this is because it too easily can end up in an
infinite loop, but for whatever reason EXCEL won't allow it.

Answer: You have to write a SUBROUTINE instead.
 

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