ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   if char is number (https://www.excelbanter.com/excel-programming/320530-if-char-number.html)

Roman Töngi

if char is number
 
How can I determine whether a char is a digit or a period by menas of VBA?
Example:
If char = 0 or char = 1 ... or char = 9 or char = "." Then
...

There is sure to be a shorter solution.

Regards,
Roman



Sharad Naik

if char is number
 
If IsNumeric(char) Then

Sharad

"Roman Töngi" wrote in message
...
How can I determine whether a char is a digit or a period by menas of VBA?
Example:
If char = 0 or char = 1 ... or char = 9 or char = "." Then
...

There is sure to be a shorter solution.

Regards,
Roman




Tom Ogilvy

if char is number
 
? isnumeric(".")
False
? isnumeric("5")
True


so
if Isnumeric(char) then
msgbox "It can be treated as a number"
else
msgbox "it can't be treated as a number"
End if

--
Regards,
Tom Ogilvy

"Roman Töngi" wrote in message
...
How can I determine whether a char is a digit or a period by menas of VBA?
Example:
If char = 0 or char = 1 ... or char = 9 or char = "." Then
...

There is sure to be a shorter solution.

Regards,
Roman





Sharad Naik

if char is number
 
Actually it should be
If IsNumeric(char) Or char = "." Then

in case you want to check if char is only a dot.
Sharad

"Roman Töngi" wrote in message
...
How can I determine whether a char is a digit or a period by menas of VBA?
Example:
If char = 0 or char = 1 ... or char = 9 or char = "." Then
...

There is sure to be a shorter solution.

Regards,
Roman




Tom Ogilvy

if char is number
 
My answer was incomplete as well. If you want to check if Char is a period
you would have to check that explicitly. However, if your use of char is
actually misleading and you want to check if a string is a number

char = 123.45

then Isnumeric(char) would be true.

if char ="A1123"

then isnumeric(char) would be false

--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote in message
...
? isnumeric(".")
False
? isnumeric("5")
True


so
if Isnumeric(char) then
msgbox "It can be treated as a number"
else
msgbox "it can't be treated as a number"
End if

--
Regards,
Tom Ogilvy

"Roman Töngi" wrote in message
...
How can I determine whether a char is a digit or a period by menas of

VBA?
Example:
If char = 0 or char = 1 ... or char = 9 or char = "." Then
...

There is sure to be a shorter solution.

Regards,
Roman







Roman Töngi

if char is number
 
just what I looked for,
thanks




All times are GMT +1. The time now is 12:23 AM.

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