ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   "Out of Context" Message? (https://www.excelbanter.com/excel-programming/305787-out-context-message.html)

Mac Lingo[_2_]

"Out of Context" Message?
 
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



Vasant Nanavati

"Out of Context" Message?
 
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.

--

Vasant

"Mac Lingo" wrote in message
nk.net...
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





Mac Lingo[_2_]

"Out of Context" Message? - The rest of the code
 
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



Vasant Nanavati

"Out of Context" Message? - The rest of the code
 
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.

--

Vasant



"Mac Lingo" wrote in message
nk.net...
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





Mac Lingo[_2_]

"Out of Context" Message?
 
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.





All times are GMT +1. The time now is 04:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com