Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Identifying the worksheet and cell that contains a function call

Hello.
I am tring to write a function that I would call from many different sheets
and cells in a workbook. The answer that the function returns is relative to
the location of the cell containing the function call.

I was thinking that I need to pass the row and column of the call, like this:
=NextTaskDueDate(ROW(FG69),COLUMN(FG69))

This works well and gives the correct result. However, I also need to pass
in the name of the sheet, because I make the function call from within many
different sheets.

Is there a way to create a 3rd parameter, which is the name of the worksheet
holding the cell containing function call?

Or, even better, is there a more effective way of identifying, within the
code within the receiving function, the location (sheet and cell reference)
of the function call?

Thanks.

Keith
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Identifying the worksheet and cell that contains a function call

Hi

Use theese statements to get the desired information in your function.

shName = ActiveSheet.Name
cRow = ActiveCell.Row
cCol = ActiveCell.Column

Regards,
Per

"Keith Howard" skrev i meddelelsen
...
Hello.
I am tring to write a function that I would call from many different
sheets
and cells in a workbook. The answer that the function returns is relative
to
the location of the cell containing the function call.

I was thinking that I need to pass the row and column of the call, like
this:
=NextTaskDueDate(ROW(FG69),COLUMN(FG69))

This works well and gives the correct result. However, I also need to pass
in the name of the sheet, because I make the function call from within
many
different sheets.

Is there a way to create a 3rd parameter, which is the name of the
worksheet
holding the cell containing function call?

Or, even better, is there a more effective way of identifying, within the
code within the receiving function, the location (sheet and cell
reference)
of the function call?

Thanks.

Keith


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Identifying the worksheet and cell that contains a function call

On Thu, 25 Dec 2008 06:25:00 -0800, Keith Howard
wrote:

Hello.
I am tring to write a function that I would call from many different sheets
and cells in a workbook. The answer that the function returns is relative to
the location of the cell containing the function call.

I was thinking that I need to pass the row and column of the call, like this:
=NextTaskDueDate(ROW(FG69),COLUMN(FG69))

This works well and gives the correct result. However, I also need to pass
in the name of the sheet, because I make the function call from within many
different sheets.

Is there a way to create a 3rd parameter, which is the name of the worksheet
holding the cell containing function call?

Or, even better, is there a more effective way of identifying, within the
code within the receiving function, the location (sheet and cell reference)
of the function call?

Thanks.

Keith


You could use the Caller property of the application object.

e.g.

===============================
Function YourUDF()
Dim sCellLoc As String
Dim r As Range, ws As Worksheet
sCellLoc = Application.Caller.Worksheet.Name & "!" & _
Application.Caller.Address

MsgBox (sCellLoc)

'or, if you want to set up range/worksheet objects
Set r = Application.Caller
Set ws = r.Worksheet

....
rest of your code
....

End Function
=======================================
--ron
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Identifying the worksheet and cell that contains a function call

On Thu, 25 Dec 2008 06:25:00 -0800, Keith Howard
wrote:

Hello.
I am tring to write a function that I would call from many different sheets
and cells in a workbook. The answer that the function returns is relative to
the location of the cell containing the function call.


Perhaps I misunderstood your question. How does the answer vary dependent on
function location?

Maybe all you need to do is specify the precedent cells?

A better explanation of what you are trying to do would be helpful.
--ron
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
how to make sure which worksheet call the function lvcha.gouqizi Excel Programming 4 October 21st 05 09:01 PM
can I call a worksheet function from within vba? G.R. Toro Excel Programming 2 September 30th 04 10:05 PM
identifying which cell calls my VBA function. y Excel Programming 3 April 26th 04 04:32 AM
Identifying cell from which a call is made David Lewis Excel Programming 1 December 11th 03 09:14 PM


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