Solved

How do I test an Excel cell for a formula ?

Posted on 2011-02-15
8
316 Views
Last Modified: 2012-06-27
Hi,
How do I test a cell in Excel if it contains a formula, rather than a number that has been entered manually ?
Can I check for the = sign in a cell ?
Thanks
Toco
0
Comment
Question by:Tocogroup
8 Comments
 
LVL 18

Expert Comment

by:Anil Golamari
ID: 34901465
Function EstFormule(rng As Range) As Boolean

EstFormule = 0
If rng.HasFormula = True Then
    EstFormule = 1
Else
End If

End Function

http://www.mrexcel.com/forum/showthread.php?t=19151
0
 

Author Comment

by:Tocogroup
ID: 34901508
Thanks for that. Is there a way of doing that without VBA ?
0
 

Expert Comment

by:thejohnsonfactor
ID: 34901777
The quick and easy answer is 'yes'.

Select the desired cell in your worksheet.  Now look in the bar at the top of the Excel window that you use to enter or edit values (or formulas in cells or charts).  This bar is called the 'Formula Bar' and it displays the constant value or formula stored in the active cell.

Formulas are equations that perform calculations on values in your worksheet. A formula starts with an equal sign (=).

For example, the following formula multiplies 2 by 3 and then adds 5 to the result:
=5+2*3
0
 

Author Comment

by:Tocogroup
ID: 34901828
Sorry, I didn't explain myself very well.

I'm setting an exercise for someone to test if they can enter formulas correctly in cells. I want to test the cell to see that they've entered the correct formula and not cheated by entering the numeric value.
For example, I want them to enter
=SUM(A3:A7)
rather than them just entering the numeric result, such as 5

If they enter the correct formula then the cell next to it displays, "CORRECT!". If it's wrong, it displays, "TRY AGAIN !"
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 81

Expert Comment

by:byundt
ID: 34901838
You can use the Excel 3 macro expression GET.CELL(48,A1) in a defined formula to tell you whether cell A1 contains a formula. It returns TRUE for cells containing formulas and FALSE otherwise.

1) Select cell B1
2) Open the Name Manager
3) Create a new name HasFormula
4) The Refers to field contains =GET.CELL(48,A1)

Use with a formula like:
=HasFormula                 'always applies to the cell to the left of cell containing the formula

If you want to use conditional formatting to highlight cells with formulas, then change the cell reference in GET.CELL to be the active cell.

You can also use F5 and Special Cells to select all cells that contain formulas.
GET.CELL.jpg
0
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 34901872
You would use HasFormula in the specific context requested like this:
=IF(A1="","",IF(AND(HasFormula,A1=5),"CORRECT","TRY AGAIN"))
0
 
LVL 81

Expert Comment

by:byundt
ID: 34901992
=GET.CELL(6,A1)      'returns the formula in cell A1 in case you want to test whether they came up with the right formula

It is important to realize that you cannot use GET.CELL directly in a worksheet formula. It may only be used with the defined formula trick described in my previous comment.

Brad
0
 

Author Closing Comment

by:Tocogroup
ID: 34902015
Excellent. Thanks very much. That's useful.

Though, I did like the simple answer of checking the formula bar !! Maybe that's the way to stop any cheating.

Thanks again
Toco
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now