Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 222
Default 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?
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace Number with Text using Macro Carter68 Excel Discussion (Misc queries) 3 April 19th 05 08:57 PM
Macro to change a number to text Lori F. Excel Programming 0 November 11th 03 04:28 PM
macro adding a number to a number already in a cell Tom Ogilvy Excel Programming 0 October 18th 03 04:34 PM
macro adding a number to a number already in a cell Don Guillett[_4_] Excel Programming 0 October 17th 03 05:21 PM
macro adding a number to a number already in a cell Ron de Bruin Excel Programming 0 October 17th 03 04:59 PM


All times are GMT +1. The time now is 01:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"