Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Reference Global vars in cell formulas?

Is it possible to reference global/public vars in cell forumulas?

I want to create a function that sets a global variable say true and false,
and have a cell formula that has an if statement:

=if([Globalvar], do something, "")

I can't use a UDF because it causes other Macros I have to fail with
RunTimeError 1004. It's something about UDFs not allowed to alter other
cells, but the UDF wouldn't be modiying cells, but my non-UDF macros are.

So, I'm experimenting with a different approach.

Ideas?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Reference Global vars in cell formulas?

Hi,

If you decalre the variable like this then it's available in all subs and
functions

Dim Globalvar

Sub nn()
Globalvar = "MyString"
Call yyy
End Sub

Sub yyy()
MsgBox Globalvar
Call MyFunc
End Sub

Private Function MyFunc()
MsgBox Globalvar
End Function

Mike

"DocBrown" wrote:

Is it possible to reference global/public vars in cell forumulas?

I want to create a function that sets a global variable say true and false,
and have a cell formula that has an if statement:

=if([Globalvar], do something, "")

I can't use a UDF because it causes other Macros I have to fail with
RunTimeError 1004. It's something about UDFs not allowed to alter other
cells, but the UDF wouldn't be modiying cells, but my non-UDF macros are.

So, I'm experimenting with a different approach.

Ideas?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Reference Global vars in cell formulas?

What Mike has mentioned is about module level variables. If you want
variables to be accessed at Workbook Level or Public Module level you will
have to use Public keyword..Refer the below 1 page article about the scope
and lifetime of variables in VBA

http://www.ozgrid.com/VBA/variable-scope-lifetime.htm

--
Jacob


"DocBrown" wrote:

Is it possible to reference global/public vars in cell forumulas?

I want to create a function that sets a global variable say true and false,
and have a cell formula that has an if statement:

=if([Globalvar], do something, "")

I can't use a UDF because it causes other Macros I have to fail with
RunTimeError 1004. It's something about UDFs not allowed to alter other
cells, but the UDF wouldn't be modiying cells, but my non-UDF macros are.

So, I'm experimenting with a different approach.

Ideas?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Reference Global vars in cell formulas?

Thanks for the quick reply.

What about reference the global var in a worksheet cell?

John

"Mike H" wrote:

Hi,

If you decalre the variable like this then it's available in all subs and
functions

Dim Globalvar

Sub nn()
Globalvar = "MyString"
Call yyy
End Sub

Sub yyy()
MsgBox Globalvar
Call MyFunc
End Sub

Private Function MyFunc()
MsgBox Globalvar
End Function

Mike

"DocBrown" wrote:

Is it possible to reference global/public vars in cell forumulas?

I want to create a function that sets a global variable say true and false,
and have a cell formula that has an if statement:

=if([Globalvar], do something, "")

I can't use a UDF because it causes other Macros I have to fail with
RunTimeError 1004. It's something about UDFs not allowed to alter other
cells, but the UDF wouldn't be modiying cells, but my non-UDF macros are.

So, I'm experimenting with a different approach.

Ideas?

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
Graph data series formulas: How to global-change all sheet reference to formula [email protected] Excel Discussion (Misc queries) 1 January 20th 09 05:32 AM
Pivot tables - can change row/col vars but can't get rid of existing vars Andreww Excel Programming 0 May 25th 07 11:50 AM
Formulas that reference cells that reference another cell Andrea Excel Discussion (Misc queries) 7 October 19th 06 08:14 AM
Changing Cell Reference in a macro on global base ashish128 Excel Discussion (Misc queries) 2 April 20th 06 01:16 PM
Global vars Nath Excel Programming 1 July 13th 04 04:20 PM


All times are GMT +1. The time now is 06:40 AM.

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

About Us

"It's about Microsoft Excel"