Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default User Defined Function - Can we identify the cell it's called from

I have a UDF and I want to identify the cell that the function is called
from. I need this because I want to be able to "conditionally" format the
cell based upon the function result and there are more than 3 conditions.
Can someone assist? I know what I need to do for the conditions, just need
to find the cell address.

Thanks,
Barb Reinhardt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default User Defined Function - Can we identify the cell it's called from

Application.caller:


Function barb() As String
barb = Application.Caller.Address
End Function
--
Gary''s Student
gsnu200711

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default User Defined Function - Can we identify the cell it's called f

Thanks. Let's say I do something like this

function barb()

Set rngWhere = Application.Caller
'do the calculations to get the value for barb
if barb = 1 then
rngwhere.interior.colorindex = 5
end if

I can see what the interior.colorindex is, but it doesn't redefine it. I'm
guessing I can't do this in a function. Can I create a sub and call it to
redefine the colors?

Thanks,
Barb Reinhardt





"Gary''s Student" wrote:

Application.caller:


Function barb() As String
barb = Application.Caller.Address
End Function
--
Gary''s Student
gsnu200711

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default User Defined Function - Can we identify the cell it's called f

I just found that UDF's are not able to do what I want to do. It would have
been so easy if they could.

Oh well.

Thanks for your assistance.
Barb Reinhardt

"Gary''s Student" wrote:

Application.caller:


Function barb() As String
barb = Application.Caller.Address
End Function
--
Gary''s Student
gsnu200711

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default User Defined Function - Can we identify the cell it's called f

You are correct, but there is still a way!. As I remember, UDFs can create
and insert comments. Not a clean as background color, but still a visible
indicator that something noteworthy has occurred.
--
Gary''s Student
gsnu200711


"Barb Reinhardt" wrote:

I just found that UDF's are not able to do what I want to do. It would have
been so easy if they could.

Oh well.

Thanks for your assistance.
Barb Reinhardt

"Gary''s Student" wrote:

Application.caller:


Function barb() As String
barb = Application.Caller.Address
End Function
--
Gary''s Student
gsnu200711



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default User Defined Function - Can we identify the cell it's called f

Roedd <<Barb Reinhardt wedi ysgrifennu:

I just found that UDF's are not able to do what I want to do. It
would have been so easy if they could.

Oh well.


Here's a post made recently to another group. It doesn't deal with colour
formatting, but with number formats, but the principle still applies:

This idea comes up from time to time and its origins are in the way that
excel responds to the user entering a worksheet function such as NOW(). Try
it. Excel not only returns the current date and time, but also reformats the
cell. This leads some people to think that a) the formattring is being done
by the function and b) it might be possible to do something similar with a
UDF. In fact, the function is not doing the formatting. Excel is registering
that the function has been entered and is responding afterwards by
'helpfully' changing the number format. An internal list, to which we have
no access, is maintained of the functions which Excel thinks might benefit
from such reformatting.

Maybe this can be done with a global sheet change event hook. We need to
check if any cell changing was unformatted ("General") before we entered our
UDF. If it is, we change the formatting to however we want it. If the UDF is
in an add-in, the whole thing can be encapsulated within the add-in
workbook.

Say we have a function called MyNow in a regular module in an Add-In:

Option Explicit

Function MyNow()
Application.Volatile
MyNow = Now()
End Function

Now (ahem!) we put the following event code in the add-in's Thisworkbook
module:

Option Explicit

Private WithEvents oApp As Excel.Application

Private Sub Workbook_Open()
Set oApp = Application
End Sub

Private Sub oApp_SheetChange(ByVal Sh As Object, _
ByVal Target As Range)
If Target.NumberFormat = "General" And _
UCase(Target.Formula) Like "=MYNOW(*)" Then _
Target.NumberFormat = "mm:ss"
End Sub

This should do what we want subject to further testing (which I'm not going
to do since I don't have any use for this!).

Rob


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
Can I Assign A User Defined Function To A Cell? smartin Excel Worksheet Functions 0 June 28th 09 10:25 PM
Excel - User Defined Function Error: This function takes no argume BruceInCalgary Excel Programming 3 August 23rd 06 08:53 PM
Color a result cell in a user defined function aaa Excel Discussion (Misc queries) 1 May 8th 06 04:16 PM
Determine the current cell while inside a User Defined Function pmax Excel Programming 2 February 1st 06 11:47 PM
current cell in user-defined function Julio Kuplinsky Excel Programming 3 December 8th 03 06:24 PM


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