Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default how to make sure which worksheet call the function

I have a function in the Sheet1, and I also call this function from
Sheet2. There are many msgbox in this function which I only want them
to execute when called by Sheet1. That is, when the function is called
by Sheet2, I don't want any msgbox shown. The problem is how I can get
to know which sheet is calling. Thanks!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default how to make sure which worksheet call the function

I would think that msgbox's in UDF's would soon get irritating to the user, but
this kind of thing works ok for me:

Option Explicit
Function myFunc()

If LCase(Application.Caller.Parent.Name) = LCase("sheet1") Then
MsgBox "hi there"
End If

myFunc = "bye there!"
End Function




"lvcha.gouqizi" wrote:

I have a function in the Sheet1, and I also call this function from
Sheet2. There are many msgbox in this function which I only want them
to execute when called by Sheet1. That is, when the function is called
by Sheet2, I don't want any msgbox shown. The problem is how I can get
to know which sheet is calling. Thanks!


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default how to make sure which worksheet call the function

Thanks. It works. But when I call from a module, it doesn't work again.
Any idea?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default how to make sure which worksheet call the function

maybe...

Option Explicit
Function myFunc()

If TypeName(Application.Caller) = "Range" Then
If LCase(Application.Caller.Parent.Name) = LCase("sheet1") Then
MsgBox "hi there"
End If
End If

myFunc = "bye there!"
End Function



"lvcha.gouqizi" wrote:

Thanks. It works. But when I call from a module, it doesn't work again.
Any idea?


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default how to make sure which worksheet call the function

Thank you very much! It works now.

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
How to call a worksheet (as a function) Bernie Excel Discussion (Misc queries) 18 April 20th 09 06:15 PM
NEED TO MAKE THE PRINT BUTTON FUNCTION IN WORKSHEET dlc-forbes Excel Worksheet Functions 2 April 9th 06 01:11 PM
How to make a function change other cells in worksheet James4U2enjoy Excel Programming 2 October 14th 05 04:45 PM
how can i make grafs for role call? people Excel Discussion (Misc queries) 0 October 9th 05 03:34 AM
can I call a worksheet function from within vba? G.R. Toro Excel Programming 2 September 30th 04 10:05 PM


All times are GMT +1. The time now is 05:03 PM.

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"