Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default static var/function question

I've got a vba function with one static variable. Is there any way the
value in the static variable can be unique to the cell calling the
function? That is, is there any way to force Excel to keep a separate
static variable for each cell that calls this function?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default static var/function question

In short no, but maybe you can circumvent it.

If there will not be many, you could create a workbook name say Sheet1_A1
and store the value there, and update it. If there are too many, is it
feasible to use cell comments to store it?

--

HTH

RP
(remove nothere from the email address if mailing direct)


wrote in message
oups.com...
I've got a vba function with one static variable. Is there any way the
value in the static variable can be unique to the cell calling the
function? That is, is there any way to force Excel to keep a separate
static variable for each cell that calls this function?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default static var/function question

Your comment storage solution sounds like it might work. Two
questions:
How do I find out the cell address from which the function is being
called?
and How do I store/retrieve the value in a cell comment?

Thanks,
Marc

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default static var/function question

Marc,

Actually that won't work at all. I was missing a beat when I suggested it,
because a worksheet function cannot modify it's environment, not setting
cell attributes (such as comments) or worksheet/workbook attributes (such as
names).

You could always use worksheet events, but it would depend upon what and how
your function works.

Apologies for that.

--

HTH

RP
(remove nothere from the email address if mailing direct)


wrote in message
oups.com...
Your comment storage solution sounds like it might work. Two
questions:
How do I find out the cell address from which the function is being
called?
and How do I store/retrieve the value in a cell comment?

Thanks,
Marc



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default static var/function question

Oh well, thanks for the stab at it though. I think I'll just go with
my first kludgie idea, which is to pass in a second argument so that
the function knows where it's being called from, and then store the
static info in an array to match against the extra argument.

-Marc



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default static var/function question

How will you save the data over different sessions of Excel?

--

HTH

RP
(remove nothere from the email address if mailing direct)


wrote in message
ups.com...
Oh well, thanks for the stab at it though. I think I'll just go with
my first kludgie idea, which is to pass in a second argument so that
the function knows where it's being called from, and then store the
static info in an array to match against the extra argument.

-Marc



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default static var/function question

On 14 Mar 2005 10:59:53 -0800, "
wrote:

I've got a vba function with one static variable. Is there any way the
value in the static variable can be unique to the cell calling the
function? That is, is there any way to force Excel to keep a separate
static variable for each cell that calls this function?


Look at the Caller Property of the Application object to obtain the address
from of the cell calling the function.

For example:

Function foo()
Dim StaticVariable As Double

Select Case Application.Caller.Address
Case Is = "$I$1"
StaticVariable = 1
Case Is = "$I$7"
StaticVariable = 7
Case Else
StaticVariable = 0
End Select

foo = StaticVariable
End Function


--ron
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
static time with if function raghav Excel Discussion (Misc queries) 2 December 4th 08 10:49 PM
Static Now() function sike11 via OfficeKB.com Excel Discussion (Misc queries) 7 April 24th 07 03:47 PM
Inserting a static date into a function FIF780 Excel Worksheet Functions 5 February 1st 07 10:39 PM
using now() as static function MINAL ZUNKE New Users to Excel 3 June 29th 05 05:04 PM
How to make the Today() function static JC Home Excel Programming 3 July 26th 03 03:57 PM


All times are GMT +1. The time now is 06:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"