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.


Reply via email to