You have to place that code in a general macro module.
Here's how I do it...
Right click any sheet tab
Select: View code
Goto the menu Insert>Module
Paste the code into the window that opens on the right
Close that application to return to Excel
Now, try the function.
Enter a simple formula in cell A1: =SUM(Z1:Z10)
Enter this formula in B1: =IsFormula(A1)
You should get a result of TRUE.
Hey Guys,You can use a VBA UDF (user defined function):
Then you'd use it just like any other worksheet function:Code:Function IsFormula(cell_ref As Range) IsFormula = cell_ref.HasFormula End Function
=IsFormula(A1)
This will return either TRUE or FALSE.
If IsFormula("B33") = True Then
code to do THIS
Else
Code to do THAT
End If
Just a note: I was receiving the same error. This did help in my situation.Maybe add this line:
Rich (BB code):Function IsFormula(cell_ref As Range) Application.Volatile IsFormula = cell_ref.HasFormula End Function