Thank you.

I probably ought to add a few "disclaimers".

The whole discussion of variables and "scope" sometimes falls under a larger 
category of "memory management".

For someone new, it often SEEMS like the easiest approach would be to simply 
declare everything as "public".

But that itself could cause problems.

Varibles that are not Public or Global are referred to as "local" variables.
These only exist while a program is running.
When the program exits, the memory is "released" and available for use by other 
applications.

Global variables keep the memory until Excel exits.
This can cause memory to be "used up" and not available for other applications.
(Some I.T. professionals refer to this as one type of "memory leak".)

---------------------------------
Most computers nowadays don't have much of a problem with this.
We have enough memory that we can "waste" some without causing problems.

Back in "the day", when "640K ought to be enough for anybody", 
an entire program had to fit on a 512k floppy,
and we thought it was GREAT when we could use the 384K of memory between 640 
and 
1024,
we had to be diligent on how we allocated memory.
Every subroutine had to release the memory as soon as it was able to. 

And "managing memory" was a major component of all programs.

Today, it's not nearly as restrictive...
But old habits....

Paul
-----------------------------------------
“Do all the good you can,
By all the means you can,
In all the ways you can,
In all the places you can,
At all the times you can,
To all the people you can,
As long as ever you can.” - John Wesley
-----------------------------------------




________________________________
From: "noorain.ans...@gmail.com" <noorain.ans...@gmail.com>
To: excel-macros@googlegroups.com
Sent: Thu, September 6, 2012 4:48:03 PM
Subject: Re: $$Excel-Macros$$ Re: UDF for all worksheets

Excellent description, we salute you Paul all group members are lucky because 
you, Asa and Don are with us.




Sent from BlackBerry® on Airtel
________________________________

From: Paul Schreiner <schreiner_p...@att.net> 
Sender: excel-macros@googlegroups.com 
Date: Thu, 6 Sep 2012 10:35:40 -0700 (PDT)
To: <excel-macros@googlegroups.com>
ReplyTo: excel-macros@googlegroups.com 
Subject: Re: $$Excel-Macros$$ Re: UDF for all worksheets

Is your function in a "Standard" module? or a "Sheet" module?

Perhaps we need a discussion about "scope".
---------------------------------------------------------------------------
First, let's talk about Declaring variables and Modules:

There are several different types of Modules:
     -ThisWorkbook (in all workbooks)
     -Sheet  (in all workbooks)  
     -Standard (can be added, defaults to names like "Module1, Module2")
     -Class (we won't get into this)

In a "Standard" module, you can place "declaration statements" (usually "Dim")
either WITHIN a function or subroutine, or OUTSIDE of a function or Subroutine.
Like:
---------------------------------------------
Dim Testvar as String

Sub Test()
   Dim TestVar as Integer
   Dim TestVar2
   MsgBox "TestVar is an Integer"
End Sub

Sub Test2()
  MsgBox "Testvar is a string"
  MsgBox "TestVar2 not defined"
End Sub
-------------------------------------------
Any variable declared WITHIN a sub or function is only available (defined) 
FOR THAT FUNCTION.
Any variable declared OUTSIDE of a sub or function is available to all 
sub/functions
WITHIN THE MODULE.

But not other modules.

If you want a variable to be defined for all sub/functions in all modules,
you have to define it as "Global" or "Public".

These terms themselves should give you an idea as to what they are doing.
"Global" : Worldwide? Everywhere?  (Hmm.. I wonder if it would work on Mars?)
"Public" : meaning "Everyone"?

==========================================
"Sheet" modules are very similar.
Except that anything defined in a Sheet module is only available to that SHEET.
Unless something has changed in Office 2010, even variables defined as "Public"
in a SHEET module will only be available to that SHEET.
If you want it available elsewhere, you need to put it in a "Standard" module.

==========================================
Functions (and Subs) work similarly.
they just change the terms slightly.

IF you place a function in a Sheet Module (Say, Sheet1)
then that function is only available to that sheet!

If you put it in a "Standard" module, then it is available to all sheets IN 
THAT 
WORKBOOK.

To make the function available "publicly", (to other workbooks)
You need to:
A) put it in a "Standard" module.
B) use the keyword "Public"

As in:  
Public Function Test()
End Function


Hope this helps explain what's going on and why.

Paul
-----------------------------------------
“Do all the good you can,
By all the means you can,
In all the ways you can,
In all the places you can,
At all the times you can,
To all the people you can,
As long as ever you can.” - John Wesley
-----------------------------------------




________________________________
From: "chhajersand...@gmail.com" <chhajersand...@gmail.com>
To: excel-macros@googlegroups.com
Sent: Thu, September 6, 2012 12:57:44 PM
Subject: Re: $$Excel-Macros$$ Re: UDF for all worksheets

Thanks Prince. I have made it public. Though I don't know the basic difference 
between the scope to be private or pubic. 

So will send you the work sheet.

Sandeep Chhajer. 
Sent on my BlackBerry® from Vodafone
________________________________

From: Prince Dubey <prince141...@gmail.com> 
Sender: excel-macros@googlegroups.com 
Date: Thu, 6 Sep 2012 04:23:22 -0700 (PDT)
To: <excel-macros@googlegroups.com>
ReplyTo: excel-macros@googlegroups.com 
Cc: <chhajersand...@gmail.com>
Subject: $$Excel-Macros$$ Re: UDF for all worksheets

Hi sandeep,

i hope scope of ur function or sub is private, so please make it public. If it 
does not work then pls share the ur workbook with us.

regards
Prince

On Thursday, September 6, 2012 4:15:13 PM UTC+5:30, sandeep chhajer wrote:
Dear all, 
>
>I have made a UDF (formula) in personal.xls file. Though it is working when I 
>am 
>working @ personal file but when ever I am trying to use it in my other 
>worksheet the formula is not working. Please help. 
>
>
>Sandeep Chhajer. 
>Sent on my BlackBerry® from Vodafone-- 
Join official facebook page of this forum @ 
https://www.facebook.com/discussexcel
 
FORUM RULES (1120+ members already BANNED for violation)
 
1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
 
2) Don't post a question in the thread of another member.
 
3) Don't post questions regarding breaking or bypassing any security measure.
 
4) Acknowledge the responses you receive, good or bad.
 
5) Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

 
6) Jobs posting is not allowed.
 
7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.
 
NOTE : Don't ever post personal or confidential data in a workbook. Forum 
owners 
and members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To post to this group, send email to excel-macros@googlegroups.com.
To unsubscribe from this group, send email to 
excel-macros+unsubscr...@googlegroups.com.
 
 
-- 
Join official facebook page of this forum @ 
https://www.facebook.com/discussexcel
 
FORUM RULES (1120+ members already BANNED for violation)
 
1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
 
2) Don't post a question in the thread of another member.
 
3) Don't post questions regarding breaking or bypassing any security measure.
 
4) Acknowledge the responses you receive, good or bad.
 
5) Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

 
6) Jobs posting is not allowed.
 
7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.
 
NOTE : Don't ever post personal or confidential data in a workbook. Forum 
owners 
and members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To post to this group, send email to excel-macros@googlegroups.com.
To unsubscribe from this group, send email to 
excel-macros+unsubscr...@googlegroups.com.
 
 
-- 
Join official facebook page of this forum @ 
https://www.facebook.com/discussexcel
 
FORUM RULES (1120+ members already BANNED for violation)
 
1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
 
2) Don't post a question in the thread of another member.
 
3) Don't post questions regarding breaking or bypassing any security measure.
 
4) Acknowledge the responses you receive, good or bad.
 
5) Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

 
6) Jobs posting is not allowed.
 
7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.
 
NOTE : Don't ever post personal or confidential data in a workbook. Forum 
owners 
and members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To post to this group, send email to excel-macros@googlegroups.com.
To unsubscribe from this group, send email to 
excel-macros+unsubscr...@googlegroups.com.
 
 
-- 
Join official facebook page of this forum @ 
https://www.facebook.com/discussexcel
 
FORUM RULES (1120+ members already BANNED for violation)
 
1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
 
2) Don't post a question in the thread of another member.
 
3) Don't post questions regarding breaking or bypassing any security measure.
 
4) Acknowledge the responses you receive, good or bad.
 
5) Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

 
6) Jobs posting is not allowed.
 
7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.
 
NOTE : Don't ever post personal or confidential data in a workbook. Forum 
owners 
and members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To post to this group, send email to excel-macros@googlegroups.com.
To unsubscribe from this group, send email to 
excel-macros+unsubscr...@googlegroups.com.

-- 
Join official facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES (1120+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

6) Jobs posting is not allowed.

7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To post to this group, send email to excel-macros@googlegroups.com.
To unsubscribe from this group, send email to 
excel-macros+unsubscr...@googlegroups.com.


Reply via email to