VBA/Excel/Access/Word/Data Type Functions/IsNumeric

Материал из VB Эксперт
Перейти к: навигация, поиск

Is the cell numeric

   <source lang="vb">

Sub ResetTest2()

   For Each n In Range("A1:A8")        "   Substitute your range here
       If IsNumeric(n) Then
           n.Value = 0
       End If
   Next n

End Sub

</source>
   
  


Use IsNumeric to check the input value

   <source lang="vb">

Sub EnterSquareRoot3()

   Dim Num As Variant
   Num = InputBox("Enter a value")
   If Not IsNumeric(Num) Then
      MsgBox "You must enter a number."
      Exit Sub
   End If
   If Num < 0 Then
       MsgBox "You must enter a positive number."
       Exit Sub
   End If
   ActiveCell.value = Sqr(Num)

End Sub

</source>