ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to tell if Cell is Text or Number (https://www.excelbanter.com/excel-programming/331119-macro-tell-if-cell-text-number.html)

Donkin[_6_]

Macro to tell if Cell is Text or Number
 

Hi

I have a macro which will carry out various commands but I would like
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 numeri
character when a number is require

--
Donki
-----------------------------------------------------------------------
Donkin's Profile: http://www.excelforum.com/member.php...fo&userid=2371
View this thread: http://www.excelforum.com/showthread.php?threadid=37702


HiArt[_2_]

Macro to tell if Cell is Text or Number
 

try

If not Isnumeric(Range("A1").value) Then... 'not a number

or


If Isnumeric(Range("A1").value) Then... 'a number

Ar

--
HiAr
-----------------------------------------------------------------------
HiArt's Profile: http://www.excelforum.com/member.php...fo&userid=1995
View this thread: http://www.excelforum.com/showthread.php?threadid=37702


Dave Peterson[_5_]

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

bigwheel

Macro to tell if Cell is Text or Number
 
Wouldn't it be better if you used Data Validation to prevent your users
entering the wrong response rather than testing for it after the event?


All times are GMT +1. The time now is 07:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com