View Full Version : [SOLVED:] Check if Excel cell is not number
Einsener37
03-16-2023, 10:40 AM
Hi!
I'm trying to check if cell in excel isn't a number.
But it gives me error.
What seems to be issue?
Sub isNotNr()
Dim input As Single
Dim WS As Worksheet
Set WS = ThisWorkbook.Worksheets("Sheet1")
input = WS.Range("B18").Value
Range("B18").Select
If input = 0 Or input < 0 Or IsNumeric(input) = False Then
MsgBox "Check input"
Exit Sub
End If
End Sub
Thanks!
JKwan
03-16-2023, 12:36 PM
perhaps you are getting error is because "input" is a keyword
Aussiebear
03-16-2023, 12:51 PM
To get the best help you should include what the error is that you are getting.
Paul_Hossler
03-16-2023, 01:10 PM
Just taking a WAG here since you didn't say what the error was or what input value caused it
Option Explicit
Sub isNotNr()
Dim N As Variant
Dim WS As Worksheet
Set WS = ThisWorkbook.Worksheets("Sheet1")
N = WS.Range("B18").Value
If IsNumeric(N) Then
If N <= 0 Then
MsgBox "Check input"
Exit Sub
End If
Else
MsgBox "Check input"
End If
End Sub
Einsener37
03-17-2023, 12:53 AM
Just taking a WAG here since you didn't say what the error was or what input value caused it
Option Explicit
Sub isNotNr()
Dim N As Variant
Dim WS As Worksheet
Set WS = ThisWorkbook.Worksheets("Sheet1")
N = WS.Range("B18").Value
If IsNumeric(N) Then
If N <= 0 Then
MsgBox "Check input"
Exit Sub
End If
Else
MsgBox "Check input"
End If
End Sub
It gave me "type mismatch" error. Then i realized from your response, that the variable data Type must be "Variant"
Muchos grazies
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.