UDF called if any cell in any workbook is changed

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,525
Office Version
  1. 365
Platform
  1. Windows
I have a UDF that is called from just one cell (D20) in just one sheet (Sheet1) in just one workbook (Book1). But if I change the contents of any cell in that sheet, or any other sheet in that workbook, or even any cell in any sheet in any open workbook, the UDF gets called. And it always gets called from Book1.Sheet1.$D$20. I know this because I am tracking the caller info using the code below.

Code:
Public Function WtdRtg(Optional p1 As String) As Variant

'Application.Volatile
Dim CallerBookName As String      'Name of calling workbook
Dim CallerSheetName As String     'Name of calling worksheet
Dim CallerCellAddr As String      'Address of calling cell
CallerBookName = Application.Caller.Worksheet.Parent.Name
CallerSheetName = Application.Caller.Worksheet.Name
CallerCellAddr = Application.Caller.Address
If p1 <> CallerSheetName Then Exit Function

I ended up adding the code above to exit the function if it wasn't called from the right sheet.

I had been fooling around with making this UDF volatile. When it was, then this behavior would occur, but then it was expected -- at least in the same workbook. But as you can see, I have commented out the Application.Volatile statement. I also did a search for "volatile" in that project and found none. I also did a search for any calls to that UDF in the workbook. None were found.

What the heck is going on here and how do I cure it? :oops:

Thanks
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Here's a bit more information. Although the caller info appears to indicate that the UDF was called from Sheet1, it gets an error trying to access a named range (cpErrMsgSw) that is local to Sheet1 and should contain either "On" or "Off". If I change the contents of a cell in Sheet2, the error message is that the named range cannot be found. If I define a range in Sheet2 with that name, then it gets the error that it does not contain the correct value.

So, it appears that the UDF is really called from Sheet2 even though the caller info says it is Sheet1.

?????
 
Upvote 0

Forum statistics

Threads
1,214,638
Messages
6,120,674
Members
448,977
Latest member
moonlight6

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