Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 211
Default How to refer to the cell containing the formula?

Hi all!

Sometimes, I usually end up in a problem while creating UDFs which refer to
the cell actually containing the same. I usually use ActiveCell technique but
in a loop in a sub procedure its OK while when used in a UDF the ActiveCell
is always different where the cursor is place.

Furthermore, sure would oblige if one would kindly provide the code for
simple formula of reversing the column values like the following, as a UDF:

=OFFSET($D$1,ROWS($D$1:$D$20)-ROWS($A$1:A1),0)

--
Thanx in advance,
Best Regards,

Faraz
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default How to refer to the cell containing the formula?

Hi Faraz,

Sometimes, I usually end up in a problem while creating UDFs which refer to
the cell actually containing the same. I usually use ActiveCell technique but
in a loop in a sub procedure its OK while when used in a UDF the ActiveCell
is always different where the cursor is place.


Application.Caller returns the range which called the UDF.

Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com
Member of:
Professional Office Developer Association
www.proofficedev.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 211
Default How to refer to the cell containing the formula?

Thanx,

Can u kindly present a clear sample code?
--
Thanx in advance,
Best Regards,

Faraz


"Jan Karel Pieterse" wrote:

Hi Faraz,

Sometimes, I usually end up in a problem while creating UDFs which refer to
the cell actually containing the same. I usually use ActiveCell technique but
in a loop in a sub procedure its OK while when used in a UDF the ActiveCell
is always different where the cursor is place.


Application.Caller returns the range which called the UDF.

Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com
Member of:
Professional Office Developer Association
www.proofficedev.com

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default How to refer to the cell containing the formula?

Hi Faraz,

Can u kindly present a clear sample code?


This function writes the addresses of the cells that call it in the immediate
window (control+g form the VBE):

Public Function Demo(r As Variant)
Dim oRng as Range
On Error Resume Next
Set oRng =Application.Caller
On Error Goto 0
If oRng Is Nothing Then
'Function called from VBA perhaps?
Else
'Function called from Worksheet cell
'Write address in immediate window (control+g)
Debug.print oRng.Address
End If

Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com
Member of:
Professional Office Developer Association
www.proofficedev.com

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
Refer cell value as part of formula Abhay Excel Worksheet Functions 1 March 18th 09 08:48 AM
How do I refer to cell in another worksheet in a formula Jim Excel Worksheet Functions 2 October 11th 08 10:37 PM
Use cell contents to refer to a sheetname in a formula cp Excel Worksheet Functions 6 September 29th 08 06:56 PM
how i can refer to cell in long formula go to another file need a help[_2_] Excel Discussion (Misc queries) 1 July 25th 08 12:34 AM
How do I refer to the tab name in a cell formula in Excel? Steven Reames Excel Discussion (Misc queries) 1 August 3rd 05 07:22 PM


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