View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_5_] Dave Peterson[_5_] is offline
external usenet poster
 
Posts: 1,758
Default Macro to tell if Cell is Text or Number

If the user types in '123 (with the leading quote), then is the cell numeric or
text?

Try this against a test worksheet:

Option Explicit
Sub aa()
Dim myCell As Range
With ActiveSheet
Set myCell = .Range("a1")
With myCell
.Value = "'123"
MsgBox IsNumeric(.Value) & "--" & Application.IsNumber(.Value)
.ClearContents
MsgBox IsNumeric(.Value) & "--" & Application.IsNumber(.Value)
End With
End With
End Sub

application.isnumber is more stringent.

Both an empty cell and '123 will come back as true using VBA's isnumeric.

Donkin wrote:

Hi

I have a macro which will carry out various commands but I would like a
line which states something like

If Range("a1"). value istext then _

If Range("a1").value isnumber then _

Where the macro can tell if the user has inputted a non numeric
character when a number is required

--
Donkin
------------------------------------------------------------------------
Donkin's Profile: http://www.excelforum.com/member.php...o&userid=23715
View this thread: http://www.excelforum.com/showthread...hreadid=377020


--

Dave Peterson