ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   NaN Validation? (https://www.excelbanter.com/excel-programming/298709-nan-validation.html)

MrPixie

NaN Validation?
 
What's the best way to validate that something is not a number (or is a
number, for that matter) in excel VBA?
I need to handle an input box with this validation.



MrPixie

NaN Validation?
 
forgot to mention - I used to do Javascript, and if you know Javascript, its
easy to do because there is the NaN function. But how to do it in excel VBA?



Chip Pearson

NaN Validation?
 
You can use the IsNumeric function to return True or False
indicating whether a character string is numeric.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"MrPixie" wrote in message
...
What's the best way to validate that something is not a number

(or is a
number, for that matter) in excel VBA?
I need to handle an input box with this validation.





Gord Dibben

NaN Validation?
 
MrPixie

Example

numbrows = InputBox("How many rows to insert")
If numbrows = "" Or Not IsNumeric(numbrows) Then
'do something

Gord Dibben Excel MVP

On Tue, 18 May 2004 18:14:20 +0100, "MrPixie" wrote:

What's the best way to validate that something is not a number (or is a
number, for that matter) in excel VBA?
I need to handle an input box with this validation.



Dave Peterson[_3_]

NaN Validation?
 
One more option is to use the application.inputbox.


Option Explicit
Sub test()
Dim myNumber As Variant
myNumber = Application.InputBox(prompt:="Number me!", Type:=1)
If myNumber = False Then
Exit Sub 'cancel
End If
'keep going
End Sub



MrPixie wrote:

What's the best way to validate that something is not a number (or is a
number, for that matter) in excel VBA?
I need to handle an input box with this validation.


--

Dave Peterson



All times are GMT +1. The time now is 10:02 PM.

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