Test If A Cell Has A Formula of Value

MikeG

Well-known Member
Joined
Jul 4, 2004
Messages
845
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
In my worksheet, Cell C3 has the Formula =SUM(A1:A10).

Sometimes a user will overwrite this formula and enter a number - e,g, 136.

In Cell C5, I would like to show a 1 if C3 still contains the formula, and a 2 if it contains a number.

I guess I'm looking for something like =ISFORMULA(C3), but I know this function does not exist.

Does anyone have a way of addressing this?

Thanks,

MikeG
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Try this UDF in a regular module

Code:
Function fmla(r As Range) As Long
fmla = IIf(r.HasFormula, 1, 2)
End Function

Then use

=fmla(A1)
 
Upvote 0
You could write a "ISFORMULA" function in VBA.

Code:
Function IsFormula(cellRef as Range) as Boolean

IsFormula = (Left(cellRef.Formula,1) = "=")

End Function

That function would return "TRUE" if the first part of the cell is "=" and would return false otherwise.
 
Upvote 0
You could write a "ISFORMULA" function in VBA.

Code:
Function IsFormula(cellRef as Range) as Boolean

IsFormula = (Left(cellRef.Formula,1) = "=")

End Function

That function would return "TRUE" if the first part of the cell is "=" and would return false otherwise.

Thanks Philip and VOG. Is there any trick so it can be done with VBA? If not, I will use VBA.

MikeG
 
Upvote 0
You could write a "ISFORMULA" function in VBA.

Code:


Function IsFormula(cellRef as Range) as BooleanIsFormula = (Left(cellRef.Formula,1) = "=")End Function
</PRE>
That function would return "TRUE" if the first part of the cell is "=" and would return false otherwise.
That would also return TRUE if = was the only thing in the cell.


Code:
Function IsFormula(r As Range) As Long
IsFormula = r.HasFormula + 2
End Function
 
Upvote 0
That would also return TRUE if = was the only thing in the cell.


Code:
Function IsFormula(r As Range) As Long
IsFormula = r.HasFormula + 2
End Function


Thanks HP.

Could you tell me where I should put the code? I did a right click on my worksheet tab and then did "View Code" and pasted it in - but the function is not available to me.

MikeG
 
Upvote 0
They all go in a regular module. Press ALT + F11, select Module from the Insert menu and paste in the code.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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