Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Formula OR value in cell? 2

Status
Not open for further replies.

macajm

Mining
Jun 5, 2001
26
0
0
AU
Can anyone tell me how to test whether a cell contains a directly input value or a formula so that I can use the test in a conditional format?
e.g. if a cell SHOWS 7, test is it a directly entered 7, or is it the result of a formula say =4+3?
 
Replies continue below

Recommended for you

Checking for a '='sign does not work in combination with a .Value instruction because .Value always gives the same result as you see in Excel. The .Formula instruction however does show the fysical input of the cell. So use this in combination with an if or case statement.

MsgBox Range("A1").Formula

For example
Entered formula 7 / =3+4
.Value 7 / 7
.Formula 7 / =3+4

Now you can check whether there's a formula or a value in the cell.

Success!

cactus13
 
There's a function =TYPE() what suppose to return 8 in the case of formula in the argument, but it never does (at least in Excel97). the other way to determine if cell contains a number or formula is to write a custom function in VBA:

Public function ISFORMULA(rng as range) as boolean
ISFORMULA=rng.hasFormula
end function

declaring a function as public will make accessible from the worksheet.
Try it!
 
If you know how to define a named ranged then try this:

Define a range
Name: IsFormula
Refers to: =LEFT(GET.CELL(6,INDIRECT("rc",FALSE)),1)="="

Then get out of this dialog box.

Next, select the all of the sells that you would like to conditionally format (that is, select all of the cells that you would like to test for a formula).

Go to the conditional format dialog box and type this condition:

Formula Is: =IsFormula

 
to: a3a
Thanks - your solution works fine & I will use it.

However I don't understand how it works, because there is no reference in Excel help index (Excel 97)to the "GET.CELL" function nor to the particular variant of the "INDIRECT" function you use.
 
To: yakpol
Thanks - your solution works fine too. I shied away from using it at first (scared of the VBA word!), but I can see now that by having it as a Public Function in my Personal.xls , that I can use it on any spreadsheet without having to enter lengthy formulae in the conditional formatting.
 
Status
Not open for further replies.
Back
Top