Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default More questions about variables and procedures...

So, I've come to find that the problem I had earlier was caused by using the
end statement, which clears the value of all variables upon it's execution.
Can anyone suggest a way to Set all variables in the auto_open macro in such
a way that their values will be maintained after code execution stops? I
would like to avoid copying all the set statements I use to each
procedure... But I suppose I will if I've got to :)

-Mike-hime


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default More questions about variables and procedures...

If you declare your variables as Public in the General Declarations (not within a module) the values will be retained after the code runs.

ie

Public SomeVariable as Integer

Sub Some_Sub()
--Your code here
end sub

Hope that gets you what you need.
TerryK
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default More questions about variables and procedures...

I was under the impression that you are correct... but even though I have
coded it that way, after I run a procedure if I try to run it agian, it will
cause an error saying that my variables aren't defined. It seems buggy to
me.

"TerryK" wrote in message
...
If you declare your variables as Public in the General Declarations (not

within a module) the values will be retained after the code runs.

ie

Public SomeVariable as Integer

Sub Some_Sub()
--Your code here
end sub

Hope that gets you what you need.
TerryK



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default More questions about variables and procedures...

Are the variables declared in the same Module or UserForm as the code that is refering to them
If not you might need to qualify them more strictly. for exampl

SomeUserForm General Declaration
Public SomeVariable as Intege

---------
Module

Sub SomeSub(
x= SomeUserForm.SomeVariabl
end su

I agree it seems buggy sometimes, I have found it best to be as explict as I can when calling variables and procedures. The small amount of extra typing gets rid of lots of unexplainable surprises

TerryK
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
Separating sub procedures JAW Excel Discussion (Misc queries) 4 January 28th 09 12:17 PM
VBA function Procedures.... Arif[_2_] Excel Worksheet Functions 1 June 3rd 08 01:54 PM
VBA functions and Procedures.... Arif[_2_] Excel Worksheet Functions 1 June 3rd 08 10:27 AM
Sequential Sub Procedures Roger[_10_] Excel Programming 3 November 20th 03 04:32 PM
Using Sub-procedures w/in a function LizUrish Excel Programming 2 November 6th 03 09:18 AM


All times are GMT +1. The time now is 07:36 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"