PC Review


Reply
Thread Tools Rate Thread

check if a cell contains a number, not text

 
 
shy1162
Guest
Posts: n/a
 
      6th Sep 2010
Is there a simple way to check if a cell contains a number, not text.
I would like to be able to verify that the cell contains a number
before doing some multiplication/division by a macro. Thanks.
excel 2000
 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      6th Sep 2010
Run the sub on separate cells that are: blank, have a number, have a date, have text, have true or false.
It can help explain why your question often generates disparate answers about the "best" way to check for "numbers".
'--
Sub ValidNumber()
Dim rng
Set rng = ActiveCell
MsgBox "IsNumber: " & Application.WorksheetFunction.IsNumber(rng) & vbCr & _
"IsNumeric: " & VBA.IsNumeric(rng) & vbCr & _
"TypeName Value: " & VBA.TypeName(rng.Value) & vbCr & _
"TypeName Value2: " & VBA.TypeName(rng.Value2) & vbCr & _
"Val-Value: " & Val(rng.Value) & vbCr & _
"Val-Value2: " & Val(rng.Value2)
End Sub
'--
This function may/might/could do what you want...

Function IsValidNumber2(ByRef rng As Excel.Range) As Boolean
'Jim Cone - September 2010
If Application.WorksheetFunction.IsNumber(rng) = True _
And VBA.IsNumeric(rng) = True Then
IsValidNumber2 = True
End If
End Function

--
Jim Cone
Portland, Oregon USA
http://tinyurl.com/TrialVersions Excel add-ins

..
..
..

"shy1162" <(E-Mail Removed)>
wrote in message
news:71163eef-720e-48b0-a0bf-(E-Mail Removed)...
Is there a simple way to check if a cell contains a number, not text.
I would like to be able to verify that the cell contains a number
before doing some multiplication/division by a macro. Thanks.
excel 2000
 
Reply With Quote
 
shy1162
Guest
Posts: n/a
 
      6th Sep 2010
Application.WorksheetFunction.IsNumber(rng)
very very very nice! Thanks
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
possible to check a cell for both even number and positivenumber..... M G Henry Microsoft Excel Discussion 3 30th Jul 2009 01:21 AM
Is there a way to check the number of different cell formats? Clay2007 Microsoft Excel Crashes 0 12th Dec 2008 10:07 PM
Check if the value of one cell can be found in a number of other c James T Kirk Microsoft Excel Programming 2 5th Nov 2008 03:35 PM
check if a cell has date or a number mona Microsoft Excel Misc 5 15th May 2008 02:39 PM
Check if a cell include number or not guyav Microsoft Excel Misc 5 23rd Jun 2004 07:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:27 AM.