NaN Validation?

M

MrPixie

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.
 
M

MrPixie

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?
 
C

Chip Pearson

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
 
G

Gord Dibben

MrPixie

Example

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

Gord Dibben Excel MVP
 
D

Dave Peterson

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
 
Top