Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default How to ID calling worksheet if it isn't the active sheet?

I have a udf that uses .ActiveSheet to identify the sheet calling it.
Works great as long as the sheet doing the calculating is the active
one.

This sheet with that udf has now been replicated - various what if
version copies. Each of these copies comes along with its own copy of
that udf in its cells. Question is, how does the udf ID the calling
sheet if it's not the currently active one?

There are global controls that change input values used by these
copied sheets. All must recalculate using this global value and their
own local variables.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default How to ID calling worksheet if it isn't the active sheet?

Application.Caller will be a Range object pointing to the cell from
which the UDF as called. E.g.,

Function Test() As String
Test = Application.Caller.Address
End Test

If, though, the function is called by other VBA code,
Application.Caller will not be a Range object. If the function is to
be called both from a worksheet cell and by other code, you should
test Application.Caller. E.g,

Function Test() As String
If IsObject(Application.Caller) Thne
If TypeOf Application.Caller Is Range Then
' called from a cell
End If
End If
End Function



Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com




On Mon, 29 Mar 2010 09:49:35 -0700 (PDT), cate
wrote:

I have a udf that uses .ActiveSheet to identify the sheet calling it.
Works great as long as the sheet doing the calculating is the active
one.

This sheet with that udf has now been replicated - various what if
version copies. Each of these copies comes along with its own copy of
that udf in its cells. Question is, how does the udf ID the calling
sheet if it's not the currently active one?

There are global controls that change input values used by these
copied sheets. All must recalculate using this global value and their
own local variables.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default How to ID calling worksheet if it isn't the active sheet?


To extend Chip's reply - here's a UDF which just returns the name of
the sheet it's on.

Function SheetName()
SheetName = Application.Caller.Parent.Name
End Function

Tim

On Mar 29, 9:49*am, cate wrote:
I have a udf that uses .ActiveSheet to identify the sheet calling it.
Works great as long as the sheet doing the calculating is the active
one.

This sheet with that udf has now been replicated - various what if
version copies. *Each of these copies comes along with its own copy of
that udf in its cells. *Question is, how does the udf ID the calling
sheet if it's not the currently active one?

There are global controls that change input values used by these
copied sheets. *All must recalculate using this global value and their
own local variables.


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
Insert a new Worksheet AFTER the existing (Active) sheet Ronnie Excel Worksheet Functions 1 January 12th 10 10:03 PM
calling from one worksheet sheet to source from another SteveDB1 Excel Programming 7 April 9th 08 10:44 PM
Calling sub from CommandButton knowing which sheet is active gtslabs Excel Programming 3 April 20th 07 10:21 PM
sending the active worksheet and an additional new sheet Qaspec Excel Programming 1 February 2nd 05 02:57 AM
Worksheet is no longer the active sheet Event Todd Huttenstine Excel Programming 3 May 21st 04 09:16 PM


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