Check for number

C

courtesio99

How do I check whether a certain cell has a number in it in code?

For example, i know Count(A1) gives 1 if cell A1 contains a valid
number instead of text. How do I do that in code?

I did the following but could not work:

If Count(Cell(1,1))>0 Then
...
End If
 
C

courtesio99

no.. wat i mean is how to check that a number is entered in cell A1
instead of text.
 
N

Norman Harker

Hi bdcrisp!

Something like:

If IsNumeric(Range("b1")) Then Range("c1") = "You have a number"



--
Regards
Norman Harker MVP (Excel)
Sydney, Australia
[email protected]
Excel and Word Function Lists (Classifications, Syntax and Arguments)
available free to good homes.
 
B

bdcrisp

if vartype(cells(1,1).value) = vbString then msgbox "It's a string"

otherwise its a number
 
C

Colo

Hi courtesio99,

IsNumeric function may can be used.
Note:Assume 3 has been inputted in A1 Cell. Nevertheless the A1 cel
has been formatted as string, IsNumeric function returns TRUE.


Code
 
D

Dave Peterson

If you may have a containing a text value that looks like a number (like
'54--leading apostrophe), you can use the worksheet function:

if application.isnumber(range("a1").value) then

This'll also dump empty cells.

if isnumeric(range("a1").value) then

will show (empty) as numeric.
 
Top