Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default How do I know which cell a function is called from?

I am calling a function like the following

Function getcurrpos(arg1 As Variant) As String
getcurrpos = Application.ActiveCell.Address
End Function

arg1 is simply a dummy -- the first time I call the function I type in the
cell reference of any cell other than the one I am calling my function from.
eg I call the function in B5 and the argument is D6

The result of the function is $B$5 as I might expect.

BUT ....

If I change the value in D6 then the function refires and the location is
not the calling cell B5 but the cell of the argument that was just selected.
This is because D6 is the active cell at this time.

What I really need is a way to tell which cell the function was called from
in the first place, which probably means that I shouldn't use ActiveCell but
use something else instead. Does anyone know how I can do this? Does the
function have any knowledge of its locality at all?

thanks for your thoughts

cheers

Murami
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,856
Default How do I know which cell a function is called from?

Why not just enter this formula in the cell?:

=ADDRESS(ROW(),COLUMN())

It will return the address in absolute format, so if you type it into
B9 it will return $B$9.

Hope this helps.

Pete

Murami wrote:

I am calling a function like the following

Function getcurrpos(arg1 As Variant) As String
getcurrpos = Application.ActiveCell.Address
End Function

arg1 is simply a dummy -- the first time I call the function I type in the
cell reference of any cell other than the one I am calling my function from.
eg I call the function in B5 and the argument is D6

The result of the function is $B$5 as I might expect.

BUT ....

If I change the value in D6 then the function refires and the location is
not the calling cell B5 but the cell of the argument that was just selected.
This is because D6 is the active cell at this time.

What I really need is a way to tell which cell the function was called from
in the first place, which probably means that I shouldn't use ActiveCell but
use something else instead. Does anyone know how I can do this? Does the
function have any knowledge of its locality at all?

thanks for your thoughts

cheers

Murami


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,440
Default How do I know which cell a function is called from?

Hi Murami,

Application.Caller.Address

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"Murami" wrote in message ...
|I am calling a function like the following
|
| Function getcurrpos(arg1 As Variant) As String
| getcurrpos = Application.ActiveCell.Address
| End Function
|
| arg1 is simply a dummy -- the first time I call the function I type in the
| cell reference of any cell other than the one I am calling my function from.
| eg I call the function in B5 and the argument is D6
|
| The result of the function is $B$5 as I might expect.
|
| BUT ....
|
| If I change the value in D6 then the function refires and the location is
| not the calling cell B5 but the cell of the argument that was just selected.
| This is because D6 is the active cell at this time.
|
| What I really need is a way to tell which cell the function was called from
| in the first place, which probably means that I shouldn't use ActiveCell but
| use something else instead. Does anyone know how I can do this? Does the
| function have any knowledge of its locality at all?
|
| thanks for your thoughts
|
| cheers
|
| Murami


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default How do I know which cell a function is called from?

Function getcurrpos() As String
getcurrpos = Application.ThisCell.Address
End Function

if you're using xl2003 or later.

"Murami" wrote:

I am calling a function like the following

Function getcurrpos(arg1 As Variant) As String
getcurrpos = Application.ActiveCell.Address
End Function

arg1 is simply a dummy -- the first time I call the function I type in the
cell reference of any cell other than the one I am calling my function from.
eg I call the function in B5 and the argument is D6

The result of the function is $B$5 as I might expect.

BUT ....

If I change the value in D6 then the function refires and the location is
not the calling cell B5 but the cell of the argument that was just selected.
This is because D6 is the active cell at this time.

What I really need is a way to tell which cell the function was called from
in the first place, which probably means that I shouldn't use ActiveCell but
use something else instead. Does anyone know how I can do this? Does the
function have any knowledge of its locality at all?

thanks for your thoughts

cheers

Murami

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
CELL Function: cell reference by formula Alex C Excel Worksheet Functions 1 June 19th 06 03:30 PM
numerical integration integreat Excel Discussion (Misc queries) 4 May 12th 06 02:40 AM
Possible Lookup Table Karen Excel Worksheet Functions 5 June 8th 05 09:43 PM
Hyperlinks using R[1]C[1] and offset function in its cell referenc Elijah-Dadda Excel Worksheet Functions 0 March 5th 05 03:31 AM
GET.CELL Biff Excel Worksheet Functions 2 November 24th 04 07:16 PM


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