PC Review


Reply
Thread Tools Rate Thread

Is a cell a formula or value?

 
 
todd
Guest
Posts: n/a
 
      31st Aug 2008
I'm stumped, I thought there used to be a =isformula to test whether a cell
is a formula or not.

How can I test for that to see if a formula got overwritten which I do want
it to do if a user chooses.
 
Reply With Quote
 
 
 
 
T. Valko
Guest
Posts: n/a
 
      31st Aug 2008
You can use a VBA UDF (user defined function):

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.

You could also use this function to conditionally format the cells.

To use this:

Open the VBE editor: ALT F11
Open the Project Explorer: CTRL R
Locate your file name in the project explorer pane on the left.
Right click the file name
Select: Insert>Module
Copy the code above and paste into the window on the right
Return back to Excel: ALT Q

Set the conditional formatting...
Select the cell(s) in question. Assume this is cell A1.
Goto Format>Conditional Formatting
Formula Is: =IsFormula(A1)
Click the Format button
Select the desired style(s)
OK out


--
Biff
Microsoft Excel MVP


"todd" <(E-Mail Removed)> wrote in message
news1C6D4CD-F5AA-484E-8233-(E-Mail Removed)...
> I'm stumped, I thought there used to be a =isformula to test whether a
> cell
> is a formula or not.
>
> How can I test for that to see if a formula got overwritten which I do
> want
> it to do if a user chooses.



 
Reply With Quote
 
Harlan Grove
Guest
Posts: n/a
 
      31st Aug 2008
"T. Valko" <biffinp...@comcast.net> wrote...
>You can use a VBA UDF (user defined function):
>
>Function IsFormula(cell_ref As Range)
>* * IsFormula = cell_ref.HasFormula
>End Function

....
>This will return either TRUE or FALSE.

....

Actually it could also return #VALUE! if you try to pass it anything
that isn't a range reference. At the risk of slight overengineering,
you could use

Function isformula(c As Variant)
If Not TypeOf c Is Range Then
isformula = CVErr(xlErrRef)
Else
isformula = c.HasFormula
End If
End Function

which would return #REF! when the argument isn't a range reference. If
this udf would be used as just one term among many in longer formulas,
this could provide more meaningful diagnostics.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Subtract cell formula from existing cell formula transferxxx@gmail.com Microsoft Excel Programming 2 12th Dec 2006 12:03 PM
How to place a cell formula after the formula result in the cell? Dmitriy Kopnichev Microsoft Excel Worksheet Functions 8 28th Nov 2003 12:22 PM
How to place a cell formula after the formula result in the cell? Dmitriy Kopnichev Microsoft Excel Discussion 10 28th Nov 2003 12:22 PM
Question: Cell formula or macro to write result of one cell to another cell Frederik Romanov Microsoft Excel Misc 1 8th Jul 2003 03:03 PM
Question: Cell formula or macro to write result of one cell to another cell Frederik Romanov Microsoft Excel Programming 1 8th Jul 2003 03:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:12 PM.