Get cell reference of UDF Caller

whitelined

New Member
Joined
Mar 24, 2009
Messages
1
Hi,

I have a UDF function to do some calculation. Based on conditions of that calculation I want to change the colour of the cell it was called on - can't do it with conditional formatting. Is it possible to get the calling cell range object?

Cheers

Aaron
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Could you not pass it as an argument?

Having said that, I'd be interested to see if there's another way to pick up this detail.
 
Upvote 0
It's Application.Caller but you can't do that from a UDF called from a cell.
 
Upvote 0
You can pick up the caller cell, eg:

Code:
Public Function MyTest() As String
    MyTest = "hello"
 
    If TypeOf Application.Caller Is Excel.Range Then MsgBox Application.Caller.Address
 
End Function


But when a UDF is called from a cell, it cannot be used to change the formatting of the cell.

For further information see here:
http://www.cpearson.com/excel/writingfunctionsinvba.aspx
 
Upvote 0

Forum statistics

Threads
1,203,047
Messages
6,053,196
Members
444,645
Latest member
mee siam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top