How to test if a specified cell contains a formula?

lovallee

Board Regular
Joined
Jul 8, 2002
Messages
220
Hello

Which formula can I use to test if a specified cell contains a formula?

Louis
 
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.


Interesting, I can follow those steps, but it only works in a conditional format statement. I cannot get it to work as a formula in a cell.
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
You can use a VBA UDF (user defined function):

Code:
Function IsFormula(cell_ref As Range)
    IsFormula = cell_ref.HasFormula
End Function
Then you'd use it just like any other worksheet function:

=IsFormula(A1)

This will return either TRUE or FALSE.
Hey Guys,

I realize this is an old post but just wondering - Is there a way to include this function in a VBA IF statement? Something like

VBA Code:
If IsFormula("B33") = True Then
   code to do THIS
Else
   Code to do THAT
End If

Thanks,
Steve K.
 
Upvote 0
Maybe add this line:

Rich (BB code):
Function IsFormula(cell_ref As Range)
    Application.Volatile
    IsFormula = cell_ref.HasFormula
End Function
Just a note: I was receiving the same error. This did help in my situation.
Thanks Biff
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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