NaN Validation?

  • Thread starter Thread starter MrPixie
  • Start date Start date
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.
 
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?
 
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

Example

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

Gord Dibben Excel MVP
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top