Col Delane
Active Member
- Joined
- Jan 14, 2014
- Messages
- 304
In the last few days I have had a problem with VBA (to apply a criterion in a filter on a different column to that with the Conditional Formatting!) not executing in a workbook using the following UDF to drive CF to alert users to cells containing a formula:
See this thread: http://www.mrexcel.com/forum/excel-questions/782589-called-subs-not-executing.html
It took a while and some detective work by Tracy from MrExcel (User = starl) & me to discover the cause. My workaround was to locate the UDF in a helper cell (i.e. one other than the one to which the CF was being applied). Why this resolves the issue I don't know.
I then did another search of the Forum and discovered a number of threads from Forum users wanting to highlight cells containing formula, many with responses from Tom Urtis suggesting the use of the Defined Name method - where a name (say "CellHasFormula") RefersTo =GET.CELL(48,INDIRECT("rc",FALSE)) is then used as the function in the custom CF formula. [I have had this in my Excel toolbox for quite some time but keep forgetting that it's there!!]
So in a test copy of my problem workbook I have now replaced the UDF with the Defined Name as the CF driver (and deleted the helper cell as well) and the VBA works fine.
My question:
Does anyone have any idea (and a plausible explanation) as to why the UDF stops [certain] VBA from executing but the Defined Name method does not?
Is it because:
Cheers
Code:
Public Function UDFHasFormula(rCell As Range) As Boolean
Application.Volatile
UDFHasFormula = rCell.HasFormula
End Function
See this thread: http://www.mrexcel.com/forum/excel-questions/782589-called-subs-not-executing.html
It took a while and some detective work by Tracy from MrExcel (User = starl) & me to discover the cause. My workaround was to locate the UDF in a helper cell (i.e. one other than the one to which the CF was being applied). Why this resolves the issue I don't know.
I then did another search of the Forum and discovered a number of threads from Forum users wanting to highlight cells containing formula, many with responses from Tom Urtis suggesting the use of the Defined Name method - where a name (say "CellHasFormula") RefersTo =GET.CELL(48,INDIRECT("rc",FALSE)) is then used as the function in the custom CF formula. [I have had this in my Excel toolbox for quite some time but keep forgetting that it's there!!]
So in a test copy of my problem workbook I have now replaced the UDF with the Defined Name as the CF driver (and deleted the helper cell as well) and the VBA works fine.
My question:
Does anyone have any idea (and a plausible explanation) as to why the UDF stops [certain] VBA from executing but the Defined Name method does not?
Is it because:
- the method uses VBA?
- the UDF is referring to its host cell within the CF formula rather than a helper cell?
- the Application.Volatile line in the UDF code?
- somethin' else?
Cheers