Test for numeric constant in a cell

X

XP

Using Win XP with Office 2007;

I would like to test the contents of a cell to determine if it contains a
numeric constant (i.e. a number, but not a date, or formula).

For example, you would use IsDate to test for a date; is there an equivalent
for a numeric constant?

1) Could an example function be posted that returns true if the current cell
contains a numeric constant?

Also, is there a type for a formula?

2) If so, could an example function be posted that returns true if the
current cell contains a formula?

3) A formula that evaluates to a number?

Thanks in advance!
 
B

Bernard Liengme

Function Ntest(mycell)
If IsDate(mycell.Value) Then
Ntest = False
ElseIf mycell.HasFormula Then
Ntest = False
Else
Ntest = WorksheetFunction.IsNumber(mycell.Value)
End If
End Function


Note that a value such as 12 typed into a cell formatted as text will return
FALSE with this UDF
best wishes
 
R

Rick Rothstein

This might work...

Function IsNumConst(Cell As Range) As Boolean
With Cell
IsNumConst = (CStr(.Value) = CStr(.Formula)) And IsNumeric(.Value2)
End With
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top